[Haskell-cafe] Re: Returning a list element?

2006-03-22 Thread Dominic Steinitz
Donald Bruce Stewart dons at cse.unsw.edu.au writes:

  mainMenu =
 sequence_ $ map putStrLn [line1, line2, line3]
 
 I argue if you want to sequence_ a map you should write mapM_:
 
 mapM_ putStrLn [line1, line2, line3]

Nice

 
 mapM is under-appreciated? More under-appreciated are line gaps:
 
 main = putStr line1\n\
   \line2\n\
   \line3\n
 

Or if you don't like hand writing in all the newlines you could use

   putStrLn . concat . intersperse \n
   



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Returning a list element?

2006-03-21 Thread Dominic Steinitz
Robert Dockins robdockins at fastmail.fm writes:

 FYI, putStrLn will automatically insert a newline for you, and the  
 final 'return ()' is unnecessary.  My favorite idiom for this kind of  
 thing is:
 
 mainMenu = putStr $ unlines
[ line 1
, line 2
, line 3
]
 
Or how about

mainMenu =
   sequence_ $ map putStrLn [line1, line2, line3]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Returning a list element?

2006-03-21 Thread Donald Bruce Stewart
dominic.steinitz:
 Robert Dockins robdockins at fastmail.fm writes:
 
  FYI, putStrLn will automatically insert a newline for you, and the  
  final 'return ()' is unnecessary.  My favorite idiom for this kind of  
  thing is:
  
  mainMenu = putStr $ unlines
 [ line 1
 , line 2
 , line 3
 ]
  
 Or how about
 
 mainMenu =
sequence_ $ map putStrLn [line1, line2, line3]

I argue if you want to sequence_ a map you should write mapM_:

mapM_ putStrLn [line1, line2, line3]

mapM is under-appreciated? More under-appreciated are line gaps:

main = putStr line1\n\
  \line2\n\
  \line3\n

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe