[Haskell-beginners] understanding curried function calls

John Wiegley johnw at newartisans.com
Wed Aug 20 10:10:57 UTC 2014


>>>>> Dimitri DeFigueiredo <defigueiredo at ucdavis.edu> writes:

> Here's a simple exercise from Stephanie Weirich's class [1] that I am having
> a hard time with.

> consider

> doTwice :: (a -> a) -> a -> a
> doTwice f x = f (f x)

> what does this do?

> ex1 :: (a -> a) -> a -> a
> ex1 = doTwice doTwice

Another way to write doTwice is:

    doTwice :: (a -> a) -> (a -> a)
    doTwice f = \x -> f (f x)

This is equivalent.  If you stare it for a while, it should answer the rest of
your questions.

John


More information about the Beginners mailing list