
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 -- View this message in context: http://www.nabble.com/Main-function-error-tp23506481p23506481.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

applebiz89 wrote:
main :: IO () main = do doFilmsInGivenYear films main
You pass as argument to 'doFilmsInGivenYear' the value 'films', which is not defined. Instead, I think you meant 'testDatabase'. All the best, -- Jochem Berndsen | jochem@functor.nl GPG: 0xE6FABFAB

On Tue, May 12, 2009 at 9:59 AM, applebiz89
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

What would you expect the program to output? You probably mean
'testDatabase' instead of 'films'.
/jve
On Tue, May 12, 2009 at 12:59 PM, applebiz89
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 -- View this message in context: http://www.nabble.com/Main-function-error-tp23506481p23506481.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

Am Dienstag 12 Mai 2009 18:59:47 schrieb applebiz89:
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
There is no top level definition of films in your module, main doesn't take any parameter, so films is not in scope in main. You probably meant testDatabase. However, main is not good even if you fix that, because every iteration of main, you work on the same database, you can't add new films or fans to films. You should do something like main :: IO () main = loop testDatabase loop db = do actionToRun <- selectAction newDB <- actionToRun db loop newDB selectAction = do putStrLn $ "Select action to run:\n 1-print films from given year\n 2-add fan for some film\n ..." ln <- getLine let n = read ln act = case n of 1 -> doFilmsInGivenYear 2 -> becomeFan .... return act doFilmInGivenYear :: [Film] -> IO [Film] doFilmInGivenYear films = do .... (your code) return films becomeFan :: [Film] -> IO [Film] becomeFan films = do who <- ask for name of fan whichFilm <- ask for film let newFilms = makeFan who whichFilm films return newFilms then you can alter your database and have the modified database available in the next iteration of loop.
[/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?
The other functions receive films as a parameter.
Thanks

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
participants (6)
-
Alexander Dunlap
-
applebiz89
-
Daniel Fischer
-
Jochem Berndsen
-
John Van Enk
-
Tillmann Rendel