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.  Function to compute the mean (Joe King)


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

Message: 1
Date: Sat, 8 May 2021 09:39:50 +0000 (UTC)
From: Joe King <joeking1...@yahoo.com>
To: "beginners@haskell.org" <beginners@haskell.org>
Subject: [Haskell-beginners] Function to compute the mean
Message-ID: <1095405637.961440.1620466790...@mail.yahoo.com>
Content-Type: text/plain; charset=UTF-8

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


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

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 2
*****************************************

Reply via email to