[Haskell-cafe] How to solve this problem?It's quite easy in PHP.
Donald Bruce Stewart
dons at cse.unsw.edu.au
Wed Feb 14 06:50:16 EST 2007
ndmitchell:
> Hi
>
> 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.
>
> Thanks
>
> Neil
$ hugs +98
__ __ __ __ ____ ___ _________________________________________
|| || || || || || ||__ Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__|| __|| Copyright (c) 1994-2005
||---|| ___|| World Wide Web: http://haskell.org/hugs
|| || Report bugs to: hugs-bugs at haskell.org
|| || Version: March 2005 _________________________________________
Haskell 98 mode: Restart with command line option -98 to enable extensions
Type :? for help
Hugs.Base> :l Text.Printf
Text.Printf> printf "%d" (1::Int) :: String
"1"
Fix YHC!
:-)
-- Don
More information about the Haskell-Cafe
mailing list