[Haskell-beginners] understanding curried function calls

Roman Czyborra roman at czyborra.com
Wed Aug 20 10:12:57 UTC 2014


Dear Dimitri:

I am having a hard time with.
> doTwice f x = f (f x)
> what does this do?  What is the systematic way to evaluate these
> expressions?


You might recognize the numeral two from pure
http://en.wikipedia.org/wiki/Lambda_calculus and the fact that some lambda
expressions are irreducible while others never arrive at such a normal form.


> Are there any resources with many practice exercises like this one?
>

None that I am aware of.  You mostly find theoretical revelations.
 Possibly because there is often nothing more practical than the right
theory.  But it is easy to make up some practical examples to play with:

let pow2 f x = f (f x) in [ pow2 (pow2 (pow2 (1+)))) 0, pow2 pow2 pow2 (1+)
0] ==  [2^3, 2^2^2^2]

Current Haskell compilers will not tell you directly that pow2 pow2 pow2
pow2 = do65536times and pow 2 pow2 (pow2 pow2) = do256times but just do so
in concrete cases.

Try pow2 pow2 (+1) 0

Or pow2 pow2 (++"-") "."

Thanks,
> Dimiti
> [1] http://www.seas.upenn.edu/~cis552/lectures/Lec2.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140820/10ab96fc/attachment.html>


More information about the Beginners mailing list