Alex Rivera | Logout

What does uncurry ($) do?

Asked 2013-04-13T21:34:26.383
15

I'm doing some excersises where I have to add a function's type and explain what it does. I'm stuck with this:

phy = uncurry ($)

The type, according to GHCi is phy :: (a -> b, a) -> b. My haskell knowledge is basic so I really have no idea what it does.

Edit
Report

1 Answer

6

The other two answers are fine. I just have a slightly different take on it.

uncurry :: (a -> b -> c) -> (a, b) -> c
($)     :: (a -> b) -> a -> b

Since the "->" in type signatures associates to the right, I can equivalently write these two type signatures like this:

uncurry :: (a -> b -> c) -> ((a, b) -> c)
($)     :: (a -> b) -> (a -> b)

uncurry takes an arbitrary function of two inputs and changes it into a funciton of one argument where that argument is a tuple of the original two arguments.

($) takes a simple one-argument function and turns it into...itself. Its only effect is syntactical. f $ is equivalent to f.

answered 2013-04-14T14:29:39.270

Your Answer