<div dir="ltr">Hello Joe,<div><br></div><div>I meant they are the same in the curried - not curried sense. I misinterpreted type constraints as actual inputs in tuple form.</div><div><br></div><div>Otherwise they are different of course :)</div><div><br></div><div>Although it depends on your specific requirements, the first one seems better for me. It also does not give type error with [Int] inputs.</div><div>And It also has one less function call as you pointed hopefully more efficient (if we don't miss other considerations)</div><div><br></div><div>Here is my little experiment with your mean function <b>but note that I let ghc infer the type for me so it has different type than yours </b>: </div><div><br></div><div><b>GHCi, version 9.0.1<br></b></div><b>ghci> let mean xs = sum xs / fromIntegral(length xs)<br>ghci> mean [2,3,5]<br>3.3333333333333335<br>ghci> :t mean<br>mean :: (Fractional a, Foldable t) => t a -> a<br></b><div><b>ghci> <br></b></div><div> <br></div><div>Regards.</div><div><br></div><div>Tarık</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 8 May 2021 at 22:36, Joe King <<a href="mailto:joeking1809@yahoo.com">joeking1809@yahoo.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">Thank Tarik<br>
<br>
> Both are the same,<br>
> Discard my previous mail <br>
<br>
Bur surely they are not both the same, as I indicated in my initial email ?<br>
<br>
Is it not the case that mean1 is a parametrically polymorphic functiion, while mean is a simple function ? <br>
<br>
My question is about the relative advantages and disadvantes of each<br>
<br>
Thanks again<br>
J<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Saturday, May 8, 2021, 02:12:26 PM GMT+1, Tarik ÖZKANLI <<a href="mailto:tozkanli2023@gmail.com" target="_blank">tozkanli2023@gmail.com</a>> wrote: <br>
<br>
<br>
<br>
<br>
<br>
No sorry,<br>
<br>
Both are the same,<br>
Discard my previous mail <br>
<br>
Regards.<br>
<br>
Tarık<br>
<br>
On Sat, 8 May 2021 at 16:07, Tarik ÖZKANLI <<a href="mailto:tozkanli2023@gmail.com" target="_blank">tozkanli2023@gmail.com</a>> wrote:<br>
> Hello,<br>
> <br>
> In standard usage there is not much difference. But in Haskell, people prefer to write in curried form (first implementation of yours) which has the advantage of using partially applied form when suitable.<br>
> <br>
> Regards.<br>
> <br>
> Tarık Özkanlı<br>
> <br>
> <br>
> On Sat, 8 May 2021 at 12:43, Joe King <<a href="mailto:joeking1809@yahoo.com" target="_blank">joeking1809@yahoo.com</a>> wrote:<br>
>> Greeetings I am new here and pretty new to Haskell.<br>
>> <br>
>> I was wondering what are the relative advanatges/disadvatnages of specifying a mean function in these two ways:<br>
>> <br>
>> mean :: [Double] -> Double<br>
>> mean xs = sum xs / fromIntegral (length xs)<br>
>> <br>
>> and<br>
>> <br>
>> mean1 :: (Real a, Fractional b) => [a] -> b<br>
>> mean1 xs = realToFrac (sum xs) / genericLength xs<br>
>> <br>
>> I understand that mean1 has the advantage that it can be called with lists of any Real type, so would work with things like <br>
>> <br>
>> foo :: [Int]<br>
>> foo = [1,2,3]<br>
>> <br>
>> mean foo<br>
>> -- type mismatch error<br>
>> <br>
>> mean1 foo<br>
>> -- no error<br>
>> <br>
>> But suppose that I know I will only ever use lists of Double, is there still any advantage (or disadvantage of using mean1). For example is there any performance benefit by using mean in that case since mean1 has additional function evaluation. <br>
>> <br>
>> Are there any other considerations ?<br>
>> <br>
>> Thanks in advance<br>
>> JK<br>
>> _______________________________________________<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>
>> <br>
> <br>
<br>
_______________________________________________<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>
_______________________________________________<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>