Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Function to compute the mean (Tarik ÖZKANLI)
   2. Re:  Function to compute the mean (Tarik ÖZKANLI)
   3. Re:  Function to compute the mean (Joe King)
   4. Re:  Function to compute the mean (Tarik ÖZKANLI)


----------------------------------------------------------------------

Message: 1
Date: Sat, 8 May 2021 16:07:46 +0300
From: Tarik ÖZKANLI <tozkanli2...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:
        <CAGxnKG_E3rTss7ZkvgyxB3S9g_e3zb=yulbfovqrhz7bhrk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <joeking1...@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@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210508/7ad1340f/attachment-0001.html>

------------------------------

Message: 2
Date: Sat, 8 May 2021 16:11:03 +0300
From: Tarik ÖZKANLI <tozkanli2...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:
        <CAGxnKG9EFv=hr9qi8bveozjddh-c9eq9tutnje2pfb6mtjw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

No sorry,

Both are the same,
Discard my previous mail

Regards.

Tarık

On Sat, 8 May 2021 at 16:07, Tarik ÖZKANLI <tozkanli2...@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 <joeking1...@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@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210508/327b61a1/attachment-0001.html>

------------------------------

Message: 3
Date: Sat, 8 May 2021 19:33:33 +0000 (UTC)
From: Joe King <joeking1...@yahoo.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID: <1008186716.1134708.1620502413...@mail.yahoo.com>
Content-Type: text/plain; charset=UTF-8

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 
<tozkanli2...@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 <tozkanli2...@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 <joeking1...@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@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> 
> 

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

Message: 4
Date: Sun, 9 May 2021 14:46:07 +0300
From: Tarik ÖZKANLI <tozkanli2...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Function to compute the mean
Message-ID:
        <cagxnkg8-d0nzwmomb7pslrmsu4njjnjj5+8ohvzos+qnvtq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello Joe,

I meant they are the same in the curried - not curried sense. I
misinterpreted type constraints as actual inputs in tuple form.

Otherwise they are different of course :)

Although it depends on your specific requirements, the first one seems
better for me. It also does not give type error with [Int] inputs.
And It also has one less function call as you pointed hopefully more
efficient (if we don't miss other considerations)

Here is my little experiment with your mean function *but note that I let
ghc infer the type for me so it has different type than yours *:


*GHCi, version 9.0.1*





*ghci> let mean xs = sum xs / fromIntegral(length xs)ghci> mean
[2,3,5]3.3333333333333335ghci> :t meanmean :: (Fractional a, Foldable t) =>
t a -> a*

*ghci> *

Regards.

Tarık

On Sat, 8 May 2021 at 22:36, Joe King <joeking1...@yahoo.com> wrote:

> 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 <
> tozkanli2...@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 <tozkanli2...@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 <joeking1...@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@haskell.org
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >>
> >
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210509/abc85983/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 154, Issue 3
*****************************************

Reply via email to