[Haskell-cafe] Getting started - help

Tillmann Rendel rendel at cs.au.dk
Thu Apr 30 08:47:07 EDT 2009


applebiz89 wrote:
> data Film = Film String String Int String 
> with this as the data. 
> testDatabase :: [Film] 
> testDatabase = [("Casino Royale", "Martin Campbell",2006, "Garry, Dave,
> Zoe")] 

Try to compile this part of the program, to get a feeling for whether 
you are on the right track. If it does not compile, try to find out 
what's wrong and correct it so that it compiles.

As you already noted in a different mail, you plan to change the 
representation of the list of fans to a list of strings (instead of a 
single string with commas). That is a good idea! So change the data 
declaration, and change the definition of testDatabase to this new 
design. Try to compile that program.

Now you can add some utility functions to work with your database. This 
will make it much easier to write a correct user interface later. For 
example, write a function

   isFan :: [Film] -> String -> String -> Bool

which checks whether someone is a fan of a film in your database. In 
other words,

   isFan testDatabase "Garry" "Casino Royale"

should be True, but

   isFan testDatabase "Peter" "Matrix"

should be False.

Another useful utility function could be

   becomeFan :: String -> String -> [Film] -> [Film]

which adds the information that someone is a fan of some film to an 
existing database. Note that this function does not do any user 
interaction, but gets the name of the fan and the name of the film as 

Think about which other utility functions you could use. Try them out in 
ghci. When you have done that, you can write a user interface which asks 
for input on the command line and uses the utility functions to keep 
track of the current database.


More information about the Haskell-Cafe mailing list