Ok, now I will try asking the right question (previous try wasn't actually an example of the problem I'm having)<br><br>Here's the code:<br><br><span style="font-family: courier new,monospace;">data Test = Test</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">data Test2 = Test2</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class MyClass a where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> getChild :: MyClass b => a -> b</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance MyClass Test where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> getChild a = Test2</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">instance MyClass Test2 where</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> getChild a = Test</span><br><br>On HUGS I get:<br><br><span style="font-family: courier new,monospace;">Error occurred</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">ERROR line 9 - Inferred type is not general enough</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">*** Expression : getChild</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">*** Expected type : (MyClass Test, MyClass a) => Test -> a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">*** Inferred type : (MyClass Test, MyClass Test2) => Test -> Test2</span><br>
<br>So, what's the problem with always returning a particular instance of MyClass? I just want to constrain it to be an instance of MyClass, nothing more.<br><br>thanks,<br><br>David<br><br><br>2009/12/18 David Gordon <<a href="mailto:david.robert.gordon@googlemail.com" target="_blank">david.robert.gordon@googlemail.com</a>><br>
><br>> Hi Folks,<br>> Total newbie here. I don't know if I am having a syntactic problem or a conceptual problem.<br>
> This code:<br>> data Test = Test<br>> data Test2 = Test2<br>> class MyClass a where<br>> getChild :: (MyClass b) => a -> b<br>> instance MyClass Test where<br>> getChild = Test2<br>> instance MyClass Test2 where<br>
> getChild = Test<br>> results in:<br>> [1 of 1] Compiling Main ( test.hs, interpreted )<br>> test.hs:10:15:<br>> Couldn't match expected type `Test -> b'<br>> against inferred type `Test2'<br>
> In the expression: Test2<br>> In the definition of `getChild': getChild = Test2<br>> In the instance declaration for `MyClass Test'<br>> test.hs:13:15:<br>> Couldn't match expected type `Test2 -> b'<br>
> against inferred type `Test'<br>> In the expression: Test<br>> In the definition of `getChild': getChild = Test<br>> In the instance declaration for `MyClass Test2'<br>> Failed, modules loaded: none.<br>
> Is this a reasonable thing to try and do in Haskell? If not, I have a lot more questions... ;)<br>> many thanks,<br>> David<br>><br><br>