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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:40:55+00:00 2026-06-17T16:40:55+00:00

Haskell newbie here. I was going through Learn you a haskell, and came across

  • 0

Haskell newbie here. I was going through Learn you a haskell, and came across this definition of the flip function.

flip' :: (a -> b -> c) -> (b -> a -> c)  
flip' f = g  
    where g x y = f y x

What I don’t get is, where did x and y come from? I mean, the signature tells me that flip' is a function that takes a function (with two parameters), and returns a function (again, with two parameters).

If I’m understanding this right, when I write a function which goes like

foo :: (a -> b) -> a -> b
foo f x = f x   -- applies the function f on x

But then, in this case I’m passing the parameter explicitly [ ie x ] and so I’m able to access it in the function body. So how come the flip' function can access the parameters x and y?

  • 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-17T16:40:56+00:00Added an answer on June 17, 2026 at 4:40 pm

    The Prelude, which is in the base package at hackage.haskell.org, is included with an implicit import in every Haskell file is where the flip function is found. On the right side you can click “source” and see the source code for flip.

    flip         :: (a -> b -> c) -> b -> a -> c
    flip f x y   =  f y x
    

    The where clause allows for local definitions, x=10 or y="bla". You can also define functions locally with the same syntax you would for the top level. add x y = x + y

    In the below equivalent formulation I make the substitution g = f y x

    flip         :: (a -> b -> c) -> b -> a -> c
    flip f x y   =  g
      where
        g = f y x
    

    Right now g takes no parameters. But what if we defined g as g a b = f b a well then we would have:

    flip         :: (a -> b -> c) -> b -> a -> c
    flip f x y   =  g x y
      where
        g a b = f b a
    

    No we can do a little algebraic cancelation(if you think of it like algebra from math class you will be pretty safe). Focusing in on:

    flip f x y   =  g x y
    

    Cancel the y on each side for:

    flip f x   =  g x
    

    Now cancel the x:

    flip f   =  g
    

    and now to put it back in the full expression:

    flip     :: (a -> b -> c) -> b -> a -> c
    flip f   =  g
      where
        g a b = f b a
    

    As a last cosmetic step we can make the substitution a to x and b to y to recover the function down to argument names:

    flip     :: (a -> b -> c) -> b -> a -> c
    flip f   =  g
      where
        g x y = f y x
    

    As you can see this definition of flip is a little round about and what we start with in the prelude is simple and is the definition I prefer. Hope that helps explain how where works and how to do a little algebraic manipulation of Haskell code.

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

Sidebar

Related Questions

I'm a haskell newbie and I couldn't find an answer to this question. Can
I'm a complete newbie currently trying to learn Haskell with Learn You a Haskell
I am a newbie in Haskell and hope this question is not silly. I
Haskell and Yesod newbie here. I've been trying to follow the Integration with Yesod
Haskell newbie here. I wrote an evaluator for a minimal assembly-like language. Now, I
I am a newbie to haskell and functional programming. This might be a very
i m a newbie to haskell, currently i need a function 'f' which, given
I'm working on learning some Haskell (please excuse the newbie error)- This routine errors
I'm a Haskell newbie, so please excuse me if you find this question trivial:
Complete Haskell newbie here, my apologies.... I am trying to create a sequence of

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.