Learn You a Haskell!


I have written several times before about using the Haskell programming language as a tool for exploring mathematics, but until now I had no good recommendation for people who were interested in learning it for that purpose (Real World Haskell is a great book if you are already a programmer and want to Get Things Done with Haskell, but not so great if you just want to have fun with it).

I am therefore happy to report that No Starch Press has just published Learn You a Haskell for Great Good! A Beginner’s Guide by Miran Lipovača. It’s a fantastic, fun, thorough introduction to Haskell, spiced up by Miran’s great sense of humor and zany illustrations. You can buy a paper copy or read it on the web for free!

Just for fun, in honor of the occasion:

> -- @powmod base exp m@ efficiently computes (base^exp (mod m)).
> powmod :: Integer -> Integer -> Integer -> Integer
> powmod _ 0 _      = 1
> powmod base exp m | even exp  = (x * x) `mod` m
>                   | otherwise = (x * x * base) `mod` m
>   where x = powmod base (exp `div` 2) m
>
> f n = powmod 2 n n
>
> -- http://oeis.org/A015910
> a015910 = map f [1..]
>
> -- http://oeis.org/A050259
> test = all (==3)
>        (map f [ 4700063497
>               , 3468371109448915
>               , 8365386194032363
>               , 10991007971508067
>               , 63130707451134435989380140059866138830623361447484274774099906755
>               ]
>        )
*Main> take 50 a015910 
[0,0,2,0,2,4,2,0,8,4,2,4,2,4,8,0,2,10,2,16,8,4,2,16,7,4,26,16,2,4,2,0,8,4,18,28,2,4,8,16,2,22,2,16,17,4,2,16,30,24]
*Main> :set +s
*Main> test
True
(0.01 secs, 1110184 bytes)

About Brent

Assistant Professor of Computer Science at Hendrix College. Functional programmer, mathematician, teacher, pianist, follower of Jesus.
This entry was posted in books, programming and tagged , , , . Bookmark the permalink.