[Haskell-cafe] displaying conetents of a list

Daniel Peebles pumpkingod at gmail.com
Sun May 10 23:42:42 EDT 2009


Even more succinctly:

sequence_ . map is mapM_, and putStrLn . show is print, so you get:

mapM_ print films

Dan

On Sun, May 10, 2009 at 9:59 PM, Alex MDC <alex.mdc at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list