[Haskell-cafe] How to solve this problem?It's quite easy in PHP.

Neil Mitchell ndmitchell at gmail.com
Wed Feb 14 06:36:03 EST 2007


Eeek, a solution that does monadic maps and require's rank 2 types!

arr = [('a',1), ('b',2), ('c',3)]
showAll = lines (map showItem arr)
showItem (a,n) = a : " = " ++ show n
main = putStr showAll

I've broken this up a bit more than usual - most people would probably
just put showAll inside main, but this separates out the concepts. arr
is the data, which you could construct with a zip if that really is
all there is to it. showItem shows a single item, showAll shows them
all, and main just prints out the information.

And this solution is Haskell 98, anything that uses printf is Haskell' only.



More information about the Haskell-Cafe mailing list