Not sure if this helps, but when you have <br><br>move :: Elements a =&gt; a<br><br>It doesn&#39;t mean move will return some unknown Elements type, it means you can choose any type which is a member of elements and move will return that type.<br>
<br>This means that<br><code style="background-color: rgb(255, 255, 187);"></code><br>Burn :: Elements a =&gt; a<br><br>implies <br><br>Burn :: Water<br><br>Which is wrong.<br><br>3 :: Double<br>3 :: Integer<br><br>are both correct on the other hand.<br>
<br>/J<br><br><br><div class="gmail_quote">On 20 August 2010 10:58, Michael Bradley <span dir="ltr">&lt;<a href="mailto:michael.bradley@hotmail.co.uk">michael.bradley@hotmail.co.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">




<div>
Hello all!<br><br>I have been experimenting with data and class declarations and came across a problem. I have been trying to do this:<br>
<br>
<div style="margin: 5px 20px 20px;">
        <div style="margin-bottom: 2px;">Code:</div>
        <pre dir="ltr" style="margin: 0px; padding: 6px; border: 1px inset; width: 750px; min-height: 194px; text-align: left; overflow: auto;">data Fire = Burn | Ember<br>data Water = Bubble | WaterGun<br><br>class Elements a<br>
<br>instance Elements Fire<br>instance Elements Water<br><br>data Elemental = Elemental { name :: String,<br>                             move :: (Elements a) =&gt; a<br>                           }</pre>
</div>So, the idea was that &quot;move&quot; in the data constructor &quot;Elemental&quot; 
would be able to take any value from either the type Fire or Water. 
However, the error message tells me this is an illegal polymorphic type.<br>
<br>
Therefore, I tried creating a function that could read my value for me 
after &quot;show&quot; was applied to the move. Hence, the data declaration for 
Elemental could now assign &quot;move&quot; to a String. The function looked like 
this:<br>
<br>
<div style="margin: 5px 20px 20px;">
        <div style="margin-bottom: 2px;">Code:</div>
        <pre dir="ltr" style="margin: 0px; padding: 6px; border: 1px inset; width: 750px; min-height: 50px; text-align: left; overflow: auto;">getMove :: (Elements b) =&gt; String -&gt; b<br>getMove x = read x :: (Elements a) =&gt; a</pre>

</div>This will not work either, as the function &quot;read&quot; complains of 
ambiguity in the letter a. I also tried this (amongst other attempts)<br>
<br>
<div style="margin: 5px 20px 20px;">
        <div style="margin-bottom: 2px;">Code:</div>
        <pre dir="ltr" style="margin: 0px; padding: 6px; border: 1px inset; width: 750px; min-height: 114px; text-align: left; overflow: auto;">getMove :: (Elements b) =&gt; String -&gt; b<br>getMove &quot;Burn&quot; = Burn<br>
getMove &quot;Ember&quot; = Ember<br>getMove &quot;Bubble&quot; = Bubble<br>getMove &quot;WaterGun&quot; = WaterGun<br>getMove _ = error &quot;Unknown move!&quot;</pre>
</div>The above caused the function to infer the type Fire, and then 
complain about the type Water. So, how can I either create a function 
that can return multiple types like I am trying to above, or is there a 
way to adjust the data declaration for Elemental?<br>
<br>
Also, I have noticed that <code style="background-color: rgb(255, 255, 187);">3 :: (Num a) =&gt; a</code> will work but <code style="background-color: rgb(255, 255, 187);">Burn :: (Elements a) =&gt; a</code> causes an ambiguity error. Why is this the case? <img src="" alt="" title="Confused" border="0"><br>

<br>
Please help!<br><br>Mike<br>
<br>                                               </div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>