[Haskell-cafe] Main function error
Alexander Dunlap
alexander.dunlap at gmail.com
Tue May 12 18:06:31 EDT 2009
On Tue, May 12, 2009 at 9:59 AM, applebiz89 <applebiz89 at hotmail.com> wrote:
>
> I have compiled each function independently and they have compiled the only
> problem is the main function..
>
> I keep getting the error 'films not defined' and I am not sure why
>
> [code]
>
> 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"])]
>
> -- Function
>
> filmsInGivenYear :: Year -> [Film] -> [String]
> filmsInGivenYear year' films = [ title | (Film title director year fans) <-
> films, year == year']
>
> doFilmsInGivenYear :: [Film] -> IO ()
> doFilmsInGivenYear films = do putStrLn "which year?"
> text <- getLine
> let year' = read text :: Int
> let answer = filmsInGivenYear year' films
> print answer
>
> main :: IO ()
> main = do
> doFilmsInGivenYear films
> main
>
> [/code]
>
> if the other functions are compiling without this error im not sure as to
> why the main function does not compile because of the films...any light on
> this?
>
> Thanks
When you say 'doFilmsInGivenYear films', where does the variable
'films' come from? It's not defined anywhere in your program. That's
what the compiler is complaining about.
Alex
More information about the Haskell-Cafe
mailing list