[Haskell-cafe] displaying conetents of a list

Michael Snoyman michael at snoyman.com
Sun May 10 22:49:01 EDT 2009


listFilms = [Film] -> IO ()
listFilms = putStrLn . show -- point free style
listFilms films = putStrLn $ show films
listFilms = mapM_ (putStrLn . show) -- put each movie on a separate line,
point free style
listFilms films = mapM_ (putStrLn . show) films

Hope that makes sense...

Michael

On Sun, May 10, 2009 at 5:30 PM, applebiz89 <applebiz89 at hotmail.com> wrote:

>
> I want to write a function to output the entire contents of a list. not
> sure
> of how to do so...This is my list i want to output
>
> type Title = String
> type Director = String
> type Year = Int
> type Fan = String
>
> data Film = Film Title Director Year [Fan] deriving Show
>
> -- List of films
>
> testDatabase :: [Film]
> testDatabase = [(Film "Casino Royale" "Martin Campbell" 2006 ["Garry",
> "Dave", "Zoe"]) ]
>
> -------
>
> I know this isnt right but this is what I have so far
>
> listFilms :: [Film] -> [Film]
> listFilms (film@(Film title director year fans) : films) = putStrLn . show
> film
>
> I know to use show and putStrLn but I just don't know how to put them into
> the function correctly
>
> thank you.
> --
> View this message in context:
> http://www.nabble.com/displaying-conetents-of-a-list-tp23470633p23470633.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090510/1649ea19/attachment.html


More information about the Haskell-Cafe mailing list