What I need to do is build a type of database. Firstly have a few questions, whether what I have done it right...and how to do something else.

This is my algebraic type for the database (correct me if its wrong)

data Film = Film String String Int String

with this as the data.

testDatabase :: [Film]
testDatabase = [("Casino Royale", "Martin Campbell",2006, "Garry, Dave, Zoe")]

the last set of strings are the fans to the film. I want to be able to add a new fan, but not sure how to specifically insert it to there

this is what I have so far:

becomeFan :: String -> String -> [Film] -> [Film]
becomeFan = do putStr "Which film are you a fan of: "
filmTitle <- getLine
do putStr "What is your name: "
fanName <- getLine
(if filmTitle == filmName then fanName : [Film])

What I need to do is build a type of database. Firstly have a few questions, whether what I have done it right...and how to do something else.

This is my algebraic type for the database (correct me if its wrong)

data Film = Film String String Int String

with this as the data.

testDatabase :: [Film] 
testDatabase = [("Casino Royale", "Martin Campbell",2006, "Garry, Dave, Zoe")]

That's broken. The expression ("Casino Royale", "Martin Campbell", 2006, "Garry, Dave, Zoe") is of type (String,String,Int,String) if we say that 2006 is of type Int. You want an expression of type Film. You need to use the Film data constructor instead of a tuple.

the last set of strings are the fans to the film. I want to be able to add a new fan, but not sure how to specifically insert it to there

If you're encoding information into a String by separating words with commas, you'd be better off using a [String] in its place.

this is what I have so far:

becomeFan :: String -> String -> [Film] -> [Film]
becomeFan = do putStr "Which film are you a fan of: "
filmTitle <- getLine
do putStr "What is your name: "
fanName <- getLine
(if filmTitle == filmName then fanName : [Film])

You should review some of the basics of how Haskell works and get comfortable with things using simpler problems.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.