Re: [Haskell-cafe] displaying conetents of a list

2009-05-12 Thread Daniel Peebles
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  wrote:
> 2009/5/11 applebiz89 
>>
>> 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@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] displaying conetents of a list

2009-05-10 Thread Alex MDC
2009/5/11 applebiz89 

> 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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] displaying conetents of a list

2009-05-10 Thread applebiz89

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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe