[Haskell-cafe] displaying conetents of a list
Alex MDC
alex.mdc at gmail.com
Sun May 10 21:59:18 EDT 2009
2009/5/11 applebiz89 <applebiz89 at hotmail.com>
> I know to use show and putStrLn but I just don't know how to put them into
> the function correctly
Well I hope we're not doing your homework for you but...
As putStrLn is in the IO monad, listFilms should at least have a signature
like this:
listFilms :: [Film] -> IO ()
Now you know you want to call putStrLn on each item in the list. That means
you want to join a bunch of functions return IO (). That sounds like a job
for sequence_:
listFilms films = sequence_ $ map (putStrLn.show) films
Or the same thing more verbosely:
listFilms [] = return ()
listFilms (film:films)
= do putStrLn (show film)
listFilms films
Hope that helps,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090510/44ee10d0/attachment.html
More information about the Haskell-Cafe
mailing list