[Haskell-cafe] haskell - main function

applebiz89 applebiz89 at hotmail.com
Sat May 9 08:48:12 EDT 2009


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 ()

-- 
View this message in context: http://www.nabble.com/haskell---main-function-tp23459841p23459841.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list