Thanks for the SO link, change the <font class="Apple-style-span" face="'courier new', monospace">Num a</font> constraint to <font class="Apple-style-span" face="'courier new', monospace">Real a</font> and using <font class="Apple-style-span" face="'courier new', 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"><<a href="mailto:jhenahan@uvm.edu">jhenahan@uvm.edu</a>></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>
> For mean xs = sum xs / length xs, I got the following:<br>
><br>
> test.hs:8:10:<br>
> No instance for (Fractional Int)<br>
> arising from a use of `/' at test.hs:8:10-27<br>
> Possible fix: add an instance declaration for (Fractional Int)<br>
> In the expression: sum xs / length xs<br>
> In the definition of `mean': mean xs = sum xs / length xs<br>
><br>
> test.hs:8:10:<br>
> Couldn't match expected type `b' against inferred type `Int'<br>
> `b' is a rigid type variable bound by<br>
> the type signature for `mean' at test.hs:7:27<br>
> In the expression: sum xs / length xs<br>
> In the definition of `mean': mean xs = sum xs / length xs<br>
><br>
> test.hs:8:19:<br>
> Couldn't match expected type `a' against inferred type `Int'<br>
> `a' is a rigid type variable bound by<br>
> the type signature for `mean' at test.hs:7:13<br>
> In the second argument of `(/)', namely `length xs'<br>
> In the expression: sum xs / length xs<br>
> In the definition of `mean': mean xs = sum xs / length xs<br>
> On Fri, Jul 1, 2011 at 2:00 PM, aditya siram <<a href="mailto:aditya.siram@gmail.com">aditya.siram@gmail.com</a>> wrote:<br>
> What compiler errors are you getting?<br>
> -deech<br>
><br>
> On Fri, Jul 1, 2011 at 12:55 AM, Ruohao Li <<a href="mailto:liruohao@gmail.com">liruohao@gmail.com</a>> wrote:<br>
> > Hi guys,<br>
> > I just started learning some Haskell. I want to implement a mean function to<br>
> > compute the mean of a list. The signature of the function is:<br>
> > mean :: (Num a, Fractional b) => [a] -> b<br>
> > But when I implement this simple function, the compiler keep whining at me<br>
> > on type errors. I know this is wrong:<br>
> > mean xs = sum xs / length xs<br>
> > But how to get it right? Thanks.<br>
> > _______________________________________________<br>
> > Haskell-Cafe mailing list<br>
> > <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> > <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>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <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>
"Computer Science is no more about computers than astronomy is about telescopes."<br>
-- Edsger Dijkstra<br>
====<br>
<br>
<br><br>
<br>
<br></blockquote></div><br></div>