[Haskell-cafe] How to solve this problem?It's quite easy in PHP.
lennart at augustsson.net
Wed Feb 14 09:06:36 EST 2007
Using printf doesn't need Haskell'. I wrote to require only Haskell98.
On Feb 14, 2007, at 11:36 , Neil Mitchell wrote:
> 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.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe