Thanks for the SO link, change the <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Num a</font> constraint to <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">Real a</font> and using <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">realToFrac</font> then it just works.<div>
<br><div class="gmail_quote">On Fri, Jul 1, 2011 at 2:11 PM, Jack Henahan <span dir="ltr">&lt;<a href="mailto:jhenahan@uvm.edu">jhenahan@uvm.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Additionally, this SO question[0] is nearly identical, and provides a little more elaboration.<br>
<br>
[0]:<a href="http://stackoverflow.com/questions/2376981/haskell-types-frustrating-a-simple-average-function" target="_blank">http://stackoverflow.com/questions/2376981/haskell-types-frustrating-a-simple-average-function</a><br>

<div><div></div><div class="h5"><br>
On Jul 1, 2011, at 2:07 AM, Ruohao Li wrote:<br>
<br>
&gt; For mean xs = sum xs / length xs, I got the following:<br>
&gt;<br>
&gt; test.hs:8:10:<br>
&gt;     No instance for (Fractional Int)<br>
&gt;       arising from a use of `/&#39; at test.hs:8:10-27<br>
&gt;     Possible fix: add an instance declaration for (Fractional Int)<br>
&gt;     In the expression: sum xs / length xs<br>
&gt;     In the definition of `mean&#39;: mean xs = sum xs / length xs<br>
&gt;<br>
&gt; test.hs:8:10:<br>
&gt;     Couldn&#39;t match expected type `b&#39; against inferred type `Int&#39;<br>
&gt;       `b&#39; is a rigid type variable bound by<br>
&gt;           the type signature for `mean&#39; at test.hs:7:27<br>
&gt;     In the expression: sum xs / length xs<br>
&gt;     In the definition of `mean&#39;: mean xs = sum xs / length xs<br>
&gt;<br>
&gt; test.hs:8:19:<br>
&gt;     Couldn&#39;t match expected type `a&#39; against inferred type `Int&#39;<br>
&gt;       `a&#39; is a rigid type variable bound by<br>
&gt;           the type signature for `mean&#39; at test.hs:7:13<br>
&gt;     In the second argument of `(/)&#39;, namely `length xs&#39;<br>
&gt;     In the expression: sum xs / length xs<br>
&gt;     In the definition of `mean&#39;: mean xs = sum xs / length xs<br>
&gt; On Fri, Jul 1, 2011 at 2:00 PM, aditya siram &lt;<a href="mailto:aditya.siram@gmail.com">aditya.siram@gmail.com</a>&gt; wrote:<br>
&gt; What compiler errors are you getting?<br>
&gt; -deech<br>
&gt;<br>
&gt; On Fri, Jul 1, 2011 at 12:55 AM, Ruohao Li &lt;<a href="mailto:liruohao@gmail.com">liruohao@gmail.com</a>&gt; wrote:<br>
&gt; &gt; Hi guys,<br>
&gt; &gt; I just started learning some Haskell. I want to implement a mean function to<br>
&gt; &gt; compute the mean of a list. The signature of the function is:<br>
&gt; &gt; mean :: (Num a, Fractional b) =&gt; [a] -&gt; b<br>
&gt; &gt; But when I implement this simple function, the compiler keep whining at me<br>
&gt; &gt; on type errors. I know this is wrong:<br>
&gt; &gt; mean xs = sum xs / length xs<br>
&gt; &gt; But how to get it right? Thanks.<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Haskell-Cafe mailing list<br>
&gt; &gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; &gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
<br>
<br>
</div></div>====<br>
&quot;Computer Science is no more about computers than astronomy is about telescopes.&quot;<br>
-- Edsger Dijkstra<br>
====<br>
<br>
<br><br>
<br>
<br></blockquote></div><br></div>