Saturday, April 14, 2012

Beginning with Haskell

I've recently started to become interested in functional languages, so I decided to give Haskell a try.
To begin with, I'm reading this book:
So far, I'm amazed with the elegance with which Haskell can be used to solve some problems. For instance, at the end of the "Starting Out" chapter, we can find this example of a problem that combines tuples and list comprehensions:
"Which right triangle that has integers for all sides and all sides equal to or smaller than 10 has a perimeter of 24?"
And this is the solution in Haskell:
ghci> [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]

Once I finish this book (this will go slow because of UOC and other projects), I have several other links to continue exploring Haskell:

No comments:

Post a Comment