[Haskell-beginners] Function to compute the mean
Joe King
joeking1809 at yahoo.com
Sat May 8 19:33:33 UTC 2021
Thank Tarik
> Both are the same,
> Discard my previous mail
Bur surely they are not both the same, as I indicated in my initial email ?
Is it not the case that mean1 is a parametrically polymorphic functiion, while mean is a simple function ?
My question is about the relative advantages and disadvantes of each
Thanks again
J
On Saturday, May 8, 2021, 02:12:26 PM GMT+1, Tarik ÖZKANLI <tozkanli2023 at gmail.com> wrote:
No sorry,
Both are the same,
Discard my previous mail
Regards.
Tarık
On Sat, 8 May 2021 at 16:07, Tarik ÖZKANLI <tozkanli2023 at gmail.com> wrote:
> Hello,
>
> 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.
>
> Regards.
>
> Tarık Özkanlı
>
>
> On Sat, 8 May 2021 at 12:43, Joe King <joeking1809 at yahoo.com> wrote:
>> Greeetings I am new here and pretty new to Haskell.
>>
>> I was wondering what are the relative advanatges/disadvatnages of specifying a mean function in these two ways:
>>
>> mean :: [Double] -> Double
>> mean xs = sum xs / fromIntegral (length xs)
>>
>> and
>>
>> mean1 :: (Real a, Fractional b) => [a] -> b
>> mean1 xs = realToFrac (sum xs) / genericLength xs
>>
>> I understand that mean1 has the advantage that it can be called with lists of any Real type, so would work with things like
>>
>> foo :: [Int]
>> foo = [1,2,3]
>>
>> mean foo
>> -- type mismatch error
>>
>> mean1 foo
>> -- no error
>>
>> 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.
>>
>> Are there any other considerations ?
>>
>> Thanks in advance
>> JK
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
More information about the Beginners
mailing list