RE: [Haskell] specification of sum
On 02 November 2005 00:20, Lennart Augustsson wrote:
Furthermore, ghc has a WRONG definition of sum.
Surely not... sum is defined by Haskell 98 as: sum = foldl (+) 0 and this is exactly what GHC provides. Furthermore we have specialised strict versions for Int and Integer. Also, we shouldn't be turning overloaded functions into class methods purely for the purposes of providing optimised versions; that's what the SPECIALISE pragma is for. Cheers, Simon
Simon Marlow wrote:
On 02 November 2005 00:20, Lennart Augustsson wrote:
Furthermore, ghc has a WRONG definition of sum.
Surely not... sum is defined by Haskell 98 as:
sum = foldl (+) 0
and this is exactly what GHC provides. Furthermore we have specialised strict versions for Int and Integer.
Also, we shouldn't be turning overloaded functions into class methods purely for the purposes of providing optimised versions; that's what the SPECIALISE pragma is for.
You are absolutly right, sum is defined with foldl. I wonder why my hbc prelude had it defined with foldr? (This should teach me not to look at bit rotted code.) -- Lennart
On Wed, Nov 02, 2005 at 11:18:13AM -0000, Simon Marlow wrote:
Also, we shouldn't be turning overloaded functions into class methods purely for the purposes of providing optimised versions; that's what the SPECIALISE pragma is for.
I am a little torn on the issue, on one hand, if it is purely for performance, then yeah, that makes sense, and SPECIALISE is a pretty key pragma for any compiler. (so much so that I have 5 variations on it in jhc :) ). however, having a default of (+) a b = sum [a,b] might be useful if sum and product are more straightforward to define for an instance than + and *. however, I don't know if this ever actually occurs in practice. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (3)
-
John Meacham -
Lennart Augustsson -
Simon Marlow