Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:41:41+00:00 2026-06-09T04:41:41+00:00

I was reading Why functional programming matters where the author implements a couple of

  • 0

I was reading Why functional programming matters where the author implements a couple of applications using foldr and function composition. I did the some of them in F# e.g. the map function:

let cons a lst = a::lst
let map f lst = List.foldBack (f>>cons) lst []

Then I wanted to implement the list filter function and got stuck:

let filter pred lst = List.foldBack (what-goes-here?) lst []

The what-goes-here? function should take as input a list item, the accumulating filtered list and return the same list if the predicate returns false and a cons:ed list if it returns true.

I guess I need the option type here but can’t figure out how to glue things together.
Is it possible to compose a function using pred and cons (and perhaps some other primitives) to achieve this without writing a custom lambda function which does all the plumbing? Is this a case for computation expressions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:41:43+00:00Added an answer on June 9, 2026 at 4:41 am

    A pragmatic answer to your question is:

    whatGoesHere = fun x xs -> if f x then x :: xs else xs
    

    Anonymous functions, if-then-else and lists are all considered
    primitives by F# practitioners. This is the clearest, most
    maintainable way to write this code.

    Alas, you have not accepted the equivalent correct answer from the
    previous responder, and you insist on seeing code involving no
    lambda expressions. You are welcome:

    ``s``s`ks``s`k`s`ks``s``s`ks``s`k`s`ks``s`k`s`kk``s
    `k`s`k``s``s`ks``s`k`s`ks``s`k`s`kk``s``s`ks``s`kki
    `ki`k`ki``s``s`ks``s`kki`ki
    `k``s``s`ks``s`kk``s`k``s``s`ks``s`kk``s`ks``s`k`s`ks
    ``s`k`s`kk``s`k`si``s`kki`k``s``s`ks
    ``s`k`s`ks``s`k`s`kk``s``s`ks``s`kki`ki
    `k`kii`ki`k`ki
    

    The above is whatGoesHere in SKI combinator calculus using a suitable
    representation of booleans and lists, printed in Unlambda notation.

    For your convenience, here is a sample compiler from untyped
    lambda calculus to SKI combinators, and the F# definitions of lambda
    calculus terms corresponding to your problem:

    http://gist.github.com/3277850

    While the equivalence of combinatory logic and lambda calculus
    makes lambda expressions unnecessary in theory, they are indispensable
    for expressing your intent as a programmer. “Why functional programming matters”
    in no way advocates avoiding lambda expressions and helper functions.
    To the contrary – the ability to define functions, including
    higher-order functions, is at the very core of functional programming.
    It hardly matters whether the functions are defined by composition or
    explicitly use lambda calculus: both are the “glue”
    the paper talks about.

    I suggest you give the paper (and perhaps its excellent references)
    another read, and then install Haskell or Clean. Given that the authors
    advocate pure lazy-by-default evaluation model, F# is not a good
    platform to explore these ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading book about OO programming in JavaScript and get some strange behaviour: function
I'm reading Pro PHP Programming and in examples the author is using parentheses around
I'm reading about functional programming and I've noticed that Pattern Matching is mentioned in
I've been reading a bit about functional programming recently and am keen to get
I'm reading the book Real-world functional programming by Tomas Petricek and Jon Skeet and
I'm reading Simon Thompson's Haskell: The Craft of Functional Programming , and I'm wondering
I have been reading templates,functors,callback function for the past week and have referred some
When reading up on functional programming I've stumbled upon the concept of Higher Order
I'm new to functional programming and as I'm reading this book. It basically says
I've been reading a lot of stuff about functional programming lately, and I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.