[Haskell-cafe] Getting started - help

Magnus Therning magnus at therning.org
Thu Apr 30 11:17:33 EDT 2009


On Thu, Apr 30, 2009 at 4:04 PM, applebiz89 <applebiz89 at hotmail.com> 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]

Change that to

  data Film = Film String String Int [String]

that way you get a constructor called `Film` for the data type `Film`:

  casinoRoyale = Film "CR" "MC" 2006 ["G", "D", "Z"]

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

Then you can create your test database either like this:

  testDatabase = [(Film "CR" "MC" 2006 ["G", "D", "Z"])]

or if you have defined `casinoRoyale` like above the like this:

  testDatabase = [casinoRoyale]

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

I think you would benefit from reading chapter 3 of RWH
http://book.realworldhaskell.org/read/defining-types-streamlining-functions.html
it offers a good introduction to defining your own types.

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


More information about the Haskell-Cafe mailing list