0

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by thoughtcoder
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.