[Haskell-beginners] understanding curried function calls

Dimitri DeFigueiredo defigueiredo at ucdavis.edu
Wed Aug 20 08:19:16 UTC 2014


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

At least, it is clear that there is a parameter to doTwice missing. So, 
I wanted to do:

ex1 y = (doTwice doTwice) y

but this gets me nowhere as I don't know how to apply the definition of 
doTwice inside
the parenthesis without naming the arguments.

What is the systematic way to evaluate these expressions? I actually got 
really
stumped when I considered.

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

I assume this is not the same as

ex2 = (doTwice doTwice doTwice) doTwice

what's being applied to what here!?
Are there any resources with many practice exercises like this one?


Thanks,


Dimitri


[1] http://www.seas.upenn.edu/~cis552/lectures/Lec2.html



More information about the Beginners mailing list