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 6326159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:13+00:00 2026-05-24T17:02:13+00:00

I’m a newbie to Haskell, and a relative newbie to functional programming. In other

  • 0

I’m a newbie to Haskell, and a relative newbie to functional programming.
In other (besides Haskell) languages, lambda forms are often very useful.

For example, in Scheme:

(define (deriv-approx f)
  (lambda (h x)
    (/ (- (f (+ x h)
          (f x)
       h)))

Would create a closure (over the function f) to approximate a derivative (at value x, with interval h).
However, this usage of a lambda form doesn’t seem to be necessary in Haskell, due to its partial application:

deriv-approx f h x = ( (f (x + h)) - (f x) ) / h

What are some examples where lambda forms are necessary in Haskell?

Edit: replaced ‘closure’ with ‘lambda form’

  • 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-05-24T17:02:13+00:00Added an answer on May 24, 2026 at 5:02 pm

    I’m going to give two slightly indirect answers.

    First, consider the following code:

    module Lambda where
    
    derivApprox f h x = ( (f (x + h)) - (f x) ) / h
    

    I’ve compiled this while telling GHC to dump an intermediate representation, which is roughly a simplified version of Haskell used as part of the compilation process, to get this:

    Lambda.derivApprox
      :: forall a. GHC.Real.Fractional a => (a -> a) -> a -> a -> a
    [LclIdX]
    Lambda.derivApprox =
      \ (@ a) ($dFractional :: GHC.Real.Fractional a) ->
        let {
          $dNum :: GHC.Num.Num a
          [LclId]
          $dNum = GHC.Real.$p1Fractional @ a $dFractional } in
        \ (f :: a -> a) (h :: a) (x :: a) ->
          GHC.Real./
            @ a
            $dFractional
            (GHC.Num.- @ a $dNum (f (GHC.Num.+ @ a $dNum x h)) (f x))
            h
    

    If you look past the messy annotations and verbosity, you should be able to see that the compiler has turned everything into lambda expressions. We can consider this an indication that you probably don’t need to do so manually.

    Conversely, let’s consider a situation where you might need lambdas. Here’s a function that uses a fold to compose a list of functions:

    composeAll :: [a -> a] -> a -> a
    composeAll = foldr (.) id
    

    What’s that? Not a lambda in sight! In fact, we can go the other way, as well:

    composeAll' :: [a -> a] -> a -> a
    composeAll' xs x = foldr (\f g x -> f (g x)) id xs x
    

    Not only is this full of lambdas, it’s also taking two arguments to the main function and, what’s more, applying foldr to all of them. Compare the type of foldr, (a -> b -> b) -> b -> [a] -> b, to the above; apparently it takes three arguments, but above we’ve applied it to four! Not to mention that the accumulator function takes two arguments, but we have a three argument lambda here. The trick, of course, is that both are returning a function that takes a single argument; and we’re simply applying that argument on the spot, instead of juggling lambdas around.

    All of which, hopefully, has convinced you that the two forms are equivalent. Lambda forms are never necessary, or perhaps always necessary, because who can tell the difference?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.