[Haskell-cafe] haskell - main function

Mads Lindstrøm mads_lindstroem at yahoo.dk
Sat May 9 10:57:12 EDT 2009


Hi

applebiz89 wrote:
> Could anyone look at this segment of code; it's not compiling wondering if
> anyone could correct me as to why. Thanks
> 
> Code:
> 
> -- Film as datatype
> type Title = String
> type Director = String
> type Year = Int
> type Fan = String
> data Film = Film Title Director Year [Fan]
> 	
> -- List of films
> 
> testDatabase :: [Film]
> testDatabase = [(Film "Casino Royale" "Martin Campbell" 2006 ["Garry",
> "Dave", "Zoe"]) ]
> 
> becomeFan :: Title -> fanName -> [Film] -> [Film]
> becomeFan _ _ [] = []
> becomeFan Title fanName ((Film Title Director Year fan):xs) 
> 	| filmName == title = (Film Title Director Year fanName:fan) : xs
> 	| otherwise = (Film Title Director Year fan) : becomeFan Title fanName xs
> 
> main :: [Film] -> IO()
> main db = 
> 	do putStr "Hi there! what is your name: "
> 	   fanName = getLine
> 	   do putStr "1 = Insert film, 2 = Become a Fan, 3 = The number of fans of
> a film, 4 = Film released in a year, 5 = Given fan, 6 = Stop : "
> 	      input = getLine
> 	      x = read input :: Int
> 	      if x == 1 
> 	         then do putStr "Enter film title: "
> 		      filmTitle <- getLine
> 		      putStr "Enter director name: "
> 		      filmDirector <- getLine
> 		      putStr "Enter release year: "
> 		      filmYear <- getLine
> 		      main insertFilm [Title Director Year [Film]]
> 	      else if x == 2
> 		   then do putStr "Enter film title: "
> 		        filmTitle <- getLine
> 		        putStr "Enter fan name: "
> 		        fanName <- getLine
> 		        main becomeFan [Title fanName]
> 	      else if x == 3
> 		   then do putStr "Enter film title: "
> 		        filmTitle <- getLine
> 		        main numberOfFans [Title]
> 	      else if x == 4
> 		   then do putStr "Enter film release year: "
> 			filmYear <- getLine
> 			main filmsInGivenYear [Year [Film]]
> 	      else if x == 5
> 		   then do putStr "Enter the fan name: "
> 			fanName <- getLine
> 			main givenUser [fanName [Film]]
> 	      else if x = 6
> 		   then return ()

You have an if without an else. You cannot have that. What should the
program do when x /= 6. And you write "x = 6" in stead of "x == 6".

But generally speaking, you want to include compiler output in "this is
not compiling"-messages to haskell-cafe.


Regards,

Mads Lindstrøm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090509/030fa4cb/attachment.bin


More information about the Haskell-Cafe mailing list