[Haskell-beginners] Enumerated types

Brent Yorgey byorgey at seas.upenn.edu
Sun Dec 27 16:24:42 EST 2009


On Sun, Dec 27, 2009 at 06:17:34PM +0100, legajid wrote:
> Thanks.
>
> for 1, i tried mapM ( putStrLn) (show pref) but show  gives only one line 
> with all values, instead of n lines with 1 value. I now understand that 
> show must be in the function that is mapped.

Right, pref is a list so (show pref) will just give you a String
representing the entire list.  You can do (map show pref) to give you
a list of Strings, one for each value.  So you could write

  mapM_ putStrLn (map show pref)

which is actually equivalent to

  mapM_ (putStrLn . show) pref

-Brent


More information about the Beginners mailing list