Re: [Haskell-cafe] curious about sum

2009-06-18 Thread Keith Sheppard
OK, I think I went off on a tangent that isn't very useful anyway thanks -Keith On Wed, Jun 17, 2009 at 6:32 PM, Lennart Augustssonlenn...@augustsson.net wrote: The creators of Haskell didn't pick any particular representation for numbers. (Well, literals are kind of In..tegers.)  You can pick

Re: [Haskell-cafe] curious about sum

2009-06-18 Thread Thomas Davie
No, I think it's extremely useful. It highlights that numbers can both be lazy and strict, and that the so called useless lazy sum, is in fact, useful. Bob On 18 Jun 2009, at 13:29, Keith Sheppard wrote: OK, I think I went off on a tangent that isn't very useful anyway thanks -Keith On

Re: [Haskell-cafe] curious about sum

2009-06-18 Thread Keith Sheppard
I don't think anyone is calling it useless at this point. I could not see a use for it initially and it was quickly pointed out that there are in fact some infrequent use cases where a lazy sum is the best option. I think this is more a discussion about principle of least surprise or which use

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Yitzchak Gale
Thomas Davie wrote: Not at all, as discussed, there are legitimate uses for a lazy sum, and haskell is a lazy language by default. Haskell is lazy by default, and we have found that to be a big win in most cases. So we don't need to be embarrassed to use strictness when that is the right thing

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Henk-Jan van Tuyl
On Wed, 17 Jun 2009 10:38:23 +0200, Yitzchak Gale g...@sefer.org wrote: While there are indeed certain very rare situations in which you want foldr or foldl for sum, they are both joltingly wrong as the default for typical usage. In practice, I find this to be a small annoyance that occurs so

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Max Rabkin
On Wed, Jun 17, 2009 at 1:07 PM, Henk-Jan van Tuylhjgt...@chello.nl wrote: On Wed, 17 Jun 2009 10:38:23 +0200, Yitzchak Gale g...@sefer.org wrote: An improved reverse function:    reverse' = foldl' (flip (:)) [] There is no need for reverse to be lazy, so this one could replace the original

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Yitzchak Gale
Henk-Jan van Tuyl wrote: reverse maximum minimum Oh yes, please fix those also! scanl scanr scanr1 iterate take drop splitAt inits Hmm, I use those all the time with large lists. They are lazy as expected, and seem to work fine. Do you have examples of problems with them? foldM

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Thomas Davie
On 17 Jun 2009, at 13:32, Yitzchak Gale wrote: Henk-Jan van Tuyl wrote: reverse maximum minimum Oh yes, please fix those also! import Prelude.Strict? Honestly, these functions are ones that I've *deffinately* used lazy versions of, in fact, in the cases of minimum/maximum I've even

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Henk-Jan van Tuyl
On Wed, 17 Jun 2009 13:32:40 +0200, Yitzchak Gale g...@sefer.org wrote: Henk-Jan van Tuyl wrote: reverse maximum minimum Oh yes, please fix those also! maximum' = foldl' max 0 [1 .. 99] minimum' = foldl' min 0 [1 .. 99] scanl scanr scanr1 iterate take drop splitAt inits Hmm,

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Henk-Jan van Tuyl
On Wed, 17 Jun 2009 18:22:51 +0200, Henk-Jan van Tuyl hjgt...@chello.nl wrote: On Wed, 17 Jun 2009 13:32:40 +0200, Yitzchak Gale g...@sefer.org wrote: Henk-Jan van Tuyl wrote: reverse maximum minimum Oh yes, please fix those also! maximum' = foldl' max 0 [1 .. 99] minimum' = foldl'

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Keith Sheppard
Haskell's numeric literals are strict. You wouldn't want that to change right? It seems to me that having sum and product be strict is consistent with this. -Keith On Wed, Jun 17, 2009 at 11:15 AM, Thomas Davietom.da...@gmail.com wrote: On 17 Jun 2009, at 13:32, Yitzchak Gale wrote: Henk-Jan

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Lennart Augustsson
What do you mean by literals are strict? Strictness is a semantic property of functions, and while literals can be overloaded to be functions I don't know what you mean. On Wed, Jun 17, 2009 at 9:50 PM, Keith Sheppardkeiths...@gmail.com wrote: Haskell's numeric literals are strict. You wouldn't

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Keith Sheppard
In lambda calculus numbers are just functions and you evaluate them just like any other function. Haskell could have chosen the same representation for numbers and all evaluation on numbers would be lazy (assuming normal order evaluation). I think that would have been the Purist Lazy way to go.

Re: [Haskell-cafe] curious about sum

2009-06-17 Thread Lennart Augustsson
The creators of Haskell didn't pick any particular representation for numbers. (Well, literals are kind of Integers.) You can pick what types you make instances of Num. Some of them are lazy, some of them are strict. On Wed, Jun 17, 2009 at 11:05 PM, Keith Sheppardkeiths...@gmail.com wrote: In

Re: [Haskell-cafe] curious about sum

2009-06-16 Thread Henning Thielemann
Jochem Berndsen schrieb: Deniz Dogan wrote: 2009/6/13 Jochem Berndsen joc...@functor.nl: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is useful if the (+)

Re: [Haskell-cafe] curious about sum

2009-06-16 Thread Henning Thielemann
On Mon, 15 Jun 2009, Don Stewart wrote: keithshep: The answer is sometimes (only if you use an optimize flag): You're turning on the strictness analyser. That's enabled with -O or -O2. But sum should be using a tail recursive foldl'. It's a bug in the H98 report, IMO. I can wrap an

Re: [Haskell-cafe] curious about sum

2009-06-16 Thread Thomas Davie
On 16 Jun 2009, at 05:18, Don Stewart wrote: keithshep: The answer is sometimes (only if you use an optimize flag): You're turning on the strictness analyser. That's enabled with -O or -O2. But sum should be using a tail recursive foldl'. It's a bug in the H98 report, IMO. Not at all, as

Re: [Haskell-cafe] curious about sum

2009-06-16 Thread Don Stewart
tom.davie: On 16 Jun 2009, at 05:18, Don Stewart wrote: keithshep: The answer is sometimes (only if you use an optimize flag): You're turning on the strictness analyser. That's enabled with -O or -O2. But sum should be using a tail recursive foldl'. It's a bug in the H98 report, IMO.

Re: [Haskell-cafe] curious about sum

2009-06-15 Thread Don Stewart
keithshep: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is strict when subject to strictness analysis (try compiling it). -- Don

Re: [Haskell-cafe] curious about sum

2009-06-15 Thread Keith Sheppard
The answer is sometimes (only if you use an optimize flag): ke...@sugarglider:~/temp/ cat sumtest.hs main = putStrLn . show . sum $ [0 .. 100] ke...@sugarglider:~/temp/ ghc --make sumtest.hs [1 of 1] Compiling Main ( sumtest.hs, sumtest.o ) Linking sumtest ...

Re: [Haskell-cafe] curious about sum

2009-06-15 Thread Keith Sheppard
I just realized... that was a statement not a question :-) anyway, thanks Keith On Mon, Jun 15, 2009 at 11:14 AM, Don Stewartd...@galois.com wrote: keithshep: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] ***

Re: [Haskell-cafe] curious about sum

2009-06-15 Thread Don Stewart
keithshep: The answer is sometimes (only if you use an optimize flag): You're turning on the strictness analyser. That's enabled with -O or -O2. But sum should be using a tail recursive foldl'. It's a bug in the H98 report, IMO. -- Don ___

Re: [Haskell-cafe] curious about sum

2009-06-14 Thread Roman Cheplyaka
* Deniz Dogan deniz.a.m.do...@gmail.com [2009-06-13 16:17:57+0200] I remember needing a non-strict sum at least once, but I do not remember the exact application. We may agree that lazy sum is sometimes (rarely) needed, but then it can be always written as fold. However, in most cases user

Re: [Haskell-cafe] curious about sum

2009-06-14 Thread Thomas Davie
On 14 Jun 2009, at 12:47, Roman Cheplyaka wrote: * Deniz Dogan deniz.a.m.do...@gmail.com [2009-06-13 16:17:57+0200] I remember needing a non-strict sum at least once, but I do not remember the exact application. We may agree that lazy sum is sometimes (rarely) needed, but then it can be

Re: [Haskell-cafe] curious about sum

2009-06-14 Thread Claus Reinke
A much better idea than making sum strict, would simply be to add a sum'. Even better to abstract over strictness, to keep a lid on code duplication? {-# LANGUAGE TypeOperators #-} sum = foldlS ($) (+) 0 sum' = foldlS ($!) (+) 0 -- identity on constructors of t (from a),

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is useful if the (+) is nonstrict; although I cannot think of any useful mathematical structure where (+) would

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Deniz Dogan
2009/6/13 Jochem Berndsen joc...@functor.nl: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is useful if the (+) is nonstrict; although I cannot think of any

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Stephan Friedrichs
Jochem Berndsen wrote: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is useful if the (+) is nonstrict; although I cannot think of any useful mathematical

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Keith Sheppard
That's an interesting example. I guess a lazy number system like that would work nicely for Deniz's use case. On Sat, Jun 13, 2009 at 10:26 AM, Stephan Friedrichsdeduktionstheo...@web.de wrote: Jochem Berndsen wrote: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Deniz Dogan wrote: 2009/6/13 Jochem Berndsen joc...@functor.nl: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow It is useful if the (+) is nonstrict; although I

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Daniel Fischer
Am Samstag 13 Juni 2009 17:00:36 schrieb Jochem Berndsen: Deniz Dogan wrote: 2009/6/13 Jochem Berndsen joc...@functor.nl: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception:

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jochem Berndsen
Daniel Fischer wrote: Am Samstag 13 Juni 2009 17:00:36 schrieb Jochem Berndsen: Deniz Dogan wrote: 2009/6/13 Jochem Berndsen joc...@functor.nl: Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100]

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Conal Elliott
You can make numeric class instances from arbitrary Applicatives [1]. I imagine a lot of them (e.g. Stream) would want at least some non-strictness. We might provide strict alternatives for sum and product. I wonder what else. [1]

Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Jake McArthur
Keith Sheppard wrote: Is there any reason that sum isn't strict? I can't think of any case where that is a good thing. Prelude sum [0 .. 100] *** Exception: stack overflow As others have said, there are cases where non-strictness is what you want. And if you are using a type that is