[Haskell-cafe] Main function error

Tillmann Rendel rendel at cs.au.dk
Tue May 12 19:29:24 EDT 2009


applebiz89 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

Well, because it is not defined :)

> 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 

At this point, the following names are defined:
   - testDatabase
   - filmsInGivenYear
   - doFilmsInGivenYear
   - main
   - (and names from libraries)

>          doFilmsInGivenYear films
>          main

Here you use three names:

   - doFilmsInGivenYear (ok, is defined)
   - films (oups, not defined)
   - main (ok, is defined)

So ghc tries to figure out what you mean with films, and fails, because 
it was not defined. Try using one of the defined names instead of films.

   Tillmann


More information about the Haskell-Cafe mailing list