[Haskell-cafe] Getting started - help

Michael Mossey mpm at alumni.caltech.edu
Thu Apr 30 11:14:58 EDT 2009

I'm intermediate-level myself so I hesitate to say something wrong, but I'll go 
ahead and point out the obvious.

applebiz89 wrote:
> Hey thanks, that was really helpful actually. I know it must be annoying for
> you, and im sorry but ive done what you said, try and compile it to see if
> it does and fix it. I have tried every possible way of using brackets in
> different place's etc (as u can tell Im not good with haskell at all) but it
> still isnt, it must be to do with my data type.
> -- Film as datatype
> data Film = String String Int [String]

This time you left something off what's called the constructor. (You had it 
there the first time!)

data Film = Film String String Int [String]

Because an algebraic data type can be constructed in potentially more than one 
way, you need a constructor. In this case, you have only one way of constructing 
a Film, so you just name the constructor Film also.

> -- List of films
> testDatabase :: [Film]
> testDatabase = ["Casino Royale", "Martin Campbell" ,2006, ["Garry", "Dave",
> "Zoe"] ]

And here your problem is that (1) you need to prefix the constructor when making 
a Film, and (2) don't use commas between arguments to the constructor. (In 
Haskell commas are for lists and tuples, and not for function arguments.) So 
this would be how to make one Film:

aFilm :: Film
aFilm = Film "Casino Royale" "Martin Campbell" 2006 ["Garry", "Dave", "Zoe"]


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

> I get this error:
> *** Expression     : ["Casino Royale","Martin
> Campbell",2006,[("Garry","Dave","Zoe")]]
> *** Term           : [("Garry","Dave","Zoe")]
> *** Type           : [([Char],[Char],[Char])]
> *** Does not match : [Char]
> Thanks alot!
> applebiz

More information about the Haskell-Cafe mailing list