<div dir="ltr"><div>This works</div><div><br></div>myAvg :: [Float] -> Float <br>myAvg [] = 0.0<br>myAvg xs = (foldr (+) 0.0 xs) / (fromIntegral (length xs) :: Float)<br><div><br></div><div>but is there a simpler way to "cast" the value of (length xs)?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 5, 2021 at 12:29 PM Ut Primum <<a href="mailto:utprimum@gmail.com">utprimum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi,<div dir="auto">when you write 3 Haskell sees it as a "num" while the type of the length [1,2,3] is "int". So 3 and length [1,2,3] have not the same type.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il ven 5 feb 2021, 19:23 Lawrence Bottorff <<a href="mailto:borgauf@gmail.com" target="_blank">borgauf@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I can divide a float by an integer<div><br></div><div>> 2.4 / 3</div>0.7999999999999999<div><br></div><div>but why can I not do this?</div><div><br></div><div>< 2.4 / (length [1,2,3])</div><div><interactive>:288:1-22: error:<br> * No instance for (Fractional Int) arising from a use of `/'<br> * In the expression: 2.4 / (length [1, 2, 3])<br></div><div><br></div><div>LB</div></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" rel="noreferrer" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>