headaches from haskell

So I’m learning Haskell, a functional programming language and I hit my first bump. First, I want to recommend Haskell: The Craft of Functional Programming. The other Haskell books I tried seemed geared more to programmers new to Haskell than they were to new programmers learning Haskell.

I knew Haskell was a strongly typed language, but didn’t realize how strong. I created the formula below to return a list of lists.

makeArray numLists lengthList = 
take lengthH (repeat (take lengthW (repeat ('.'))))


makeArray 3 5

would result in a list containing 3 lists of 5 characters each.

My formula has a type of

Int -> Int -> [[Char]]

Initially, I took this to mean that the type was [[Char]]. Then I tried to use makeArray with other formulas expecting a type of [[Char]] and found that Int -> Int -> [[Char]] and [[Char]] are two different types for Haskell.

For Haskell, the end result is not the type, the process is the type. And my mind is blown by how powerful and stable Haskell is because of this. I come from a land of scripting. You don’t step in the same river twice in scripting; things are always flowing along and changing as they go. Not so in Haskell. In Haskell, no matter how many times you step in the river, it’s always the same river.

I love the headaches Haskell gives me. I feel like Zeus birthing Minerva (Athena).

13. July 2014 by sojourner hardeman
Categories: geekery | Tags: | Leave a comment

Leave a Reply

Required fields are marked *