Thoughts Heap

A Blog by Roman Gonzalez.-

RSS
May
7th
Thu
permalink

Good Headaches, complements of Haskell (part 1)

Right now I’m almost finishing the ch. 6 of Real World Haskell, what a good headache I got with the definition of the function Control.Arrow.second

here I leave you with a GHCI session to understand my pain



>> :t second

second :: (Arrow a) => a b c -> a (d, b) (d, c)

WTF moment right there… what tha hell does “a b c” stands for?, this letters separated only by spaces on a function defintion get the creaps out of me.

After poking around with the function, I got what it does



>> let upcase = map toUpper

>> :t (second upcase)

second upcase :: (d, [Char]) -> (d, [Char])

This makes more sense to me now, second is a higher level function used for easy transformation of tuples. Enough said, I think watching how it goes is better than any explination I can came up with.



>> (second upcase) ("hard", "lessons")

("hard", "LESSONS")

>> map (second upcase) [("this", "is"), ("a", "hard"), ("lesson", "rwh")]

[("this", "IS"), ("a", "HARD"), ("lesson", "RWH")]

So this is pretty neat for collection of tuples… as it may seem.

blog comments powered by Disqus