[Haskell-beginners] Type constraints question

David Gordon david.robert.gordon at googlemail.com
Fri Dec 18 05:54:03 EST 2009


Hi Folks,

Total newbie here. I don't know if I am having a syntactic problem or a
conceptual problem.

This code:

data Test = Test

data Test2 = Test2

class MyClass a where
    getChild :: (MyClass b) => a -> b

instance MyClass Test where
    getChild = Test2

instance MyClass Test2 where
    getChild = Test

results in:

[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:10:15:
    Couldn't match expected type `Test -> b'
           against inferred type `Test2'
    In the expression: Test2
    In the definition of `getChild': getChild = Test2
    In the instance declaration for `MyClass Test'

test.hs:13:15:
    Couldn't match expected type `Test2 -> b'
           against inferred type `Test'
    In the expression: Test
    In the definition of `getChild': getChild = Test
    In the instance declaration for `MyClass Test2'
Failed, modules loaded: none.

Is this a reasonable thing to try and do in Haskell? If not, I have a lot
more questions... ;)

many thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091218/ef193dce/attachment.html


More information about the Beginners mailing list