Building lists of data types in Haskell

I'm really confused about how your supposed to get data out of typeclasses in haskell. I'm coming for a C background so finding it really difficult that you can't just access the data. What I have is something like this:

data MyType = MyType String deriving (Show)


display :: [MyType] -> IO ()
display ((MyType name):xs) = do
       display xs
       putStr name

Basically here I want to access 'name' however it just doesn't seem to work. Can I access the data within an instance of a typeclass by just having a reference to the object in my code or do I have to map its contents to variables? and if so how?

Links to good tutorials on this would be appreciated, I've read 'Learn you a Haskell for great good' but when I try to deviate from the examples given there always seems to be to much I need to know to get it done. -A

5
задан Don Stewart 4 May 2011 в 19:38
поделиться