<div class="gmail_quote">In addition to fixing 'Float', you should define the 'Fractional' instance for MathExpression. This would let you use:<div class="im"><div> let pi = 3.14 :: MathExpression</div><div>
<br></div></div><div>So your instance of Fractional would look like:</div>
<div><br></div><div> </div><font face="'courier new', monospace">instance Num MathExpression where<br></font><div><div><font face="'courier new', monospace"> (+) a b = Add a b</font></div>
<div><font face="'courier new', monospace"> (*) a b = Multiply a b</font></div><div><font face="'courier new', monospace"> (-) a b = Subtract a b</font></div>
<div><font face="'courier new', monospace"> negate b = Subtract 0 b</font></div><div><font face="'courier new', monospace"> fromInteger = MathFloat . fromInteger</font></div>
<div><font face="'courier new', monospace"> abs = undefined</font></div><div><font face="'courier new', monospace"> signum = undefined</font></div><div>
<font face="'courier new', monospace">instance Fractional MathExpression where<br> fromRational = MathFloat . fromRational<br></font><font face="'courier new', monospace"> (/) a b = Divide a b<br>
</font><font face="'courier new', monospace"> recip b = Divide 1 b</font></div><div><font face="'courier new', monospace"> <br></font><div><div><div><div>
<div class="gmail_quote"><font face="arial, helvetica, sans-serif">That would give 'fromRational' and 'fromInteger' which are the main numeric conversion functions.</font></div><div class="gmail_quote">
<font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif">Regards,</font></div><div class="gmail_quote">
<font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_quote"><font face="arial, helvetica, sans-serif">Dave</font></div><div class="im"><div class="gmail_quote"><font face="'courier new', monospace"><br>
</font></div><div class="gmail_quote">On Fri, Aug 19, 2011 at 1:40 PM, Paul Reiners <span dir="ltr"><<a href="mailto:paul.reiners@gmail.com" target="_blank">paul.reiners@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've created a simple type declaration:<br><br><div style="margin-left:40px"><span style="font-family:courier new,monospace">data MathExpression = Float</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> | Add MathExpression MathExpression</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> | Subtract MathExpression MathExpression</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> | Multiply MathExpression MathExpression</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> | Divide MathExpression MathExpression</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> deriving (Show)</span><br>
</div><br>Now how do I create an instance of MathExpression which is just a Float?<br></blockquote><div><br></div></div></div></div></div></div></div></div></div>
</div><br>