Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Johan Tibell
I agree that (in this context, beginning learning Haskell) it is a somewhat minor issue. But I disagree that this is something you should ignore until it becomes a problem and I do think that it should be part of learning Haskell. Properly using strictness is an important part of using

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread PR Stanley
That's a very good point. Yes, let's have some detailed explanations accompanied by some good examples. Cheers, Paul At 08:43 03/12/2007, you wrote: I agree that (in this context, beginning learning Haskell) it is a somewhat minor issue. But I disagree that this is something you should

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Bulat Ziganshin
Hello PR, Monday, December 3, 2007, 8:20:35 AM, you wrote: occurs m (Node l n r) = m == n || occurs m l || occurs m r in terms of style, i can prefer occurs m (Node l n r) = or [m==n, occurs m l, occurs m r] -- Best regards, Bulatmailto:[EMAIL PROTECTED]

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Ketil Malde
Johan Tibell [EMAIL PROTECTED] writes: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still quite poor and I feel I can't make informed decisions on

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Derek Elkins
On Mon, 2007-12-03 at 10:48 +0100, Ketil Malde wrote: Johan Tibell [EMAIL PROTECTED] writes: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Andrew Coppin
Johan Tibell wrote: It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still quite poor and I feel I can't make informed decisions on when I need to make

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread ajb
G'day all. On Mon, 2007-12-03 at 10:48 +0100, Ketil Malde wrote: I find that I often need to add strictness when: left thumb) parsing [Char] into something more compact, i.e. almost all cases. right thumb) storing data into maps, especially when the values are produced by

Re: [Haskell-cafe] Possible Improvements

2007-12-03 Thread Felipe Lessa
On Dec 3, 2007 9:23 PM, [EMAIL PROTECTED] wrote: 2. If it's logically a Functor, strictness will break the axioms, so don't do that. What do you mean by breaking the axioms? If I define data List a = Nil | Cons !a !(List a) instance Functor List where fmap f Nil = Nil fmap f (Cons x

[Haskell-cafe] Possible Improvements

2007-12-02 Thread PR Stanley
Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any way. Thanks, Paul ___

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Don Stewart
prstanley: Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any way. You could probably get away with: data Tree =

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Tim Chevalier
On 12/2/07, Don Stewart [EMAIL PROTECTED] wrote: prstanley: Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Don Stewart
catamorphism: On 12/2/07, Don Stewart [EMAIL PROTECTED] wrote: prstanley: Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Don Stewart
Fully lazy: data Tree = Leaf Int | Node Tree Int Tree $ time ./A 25 49 ./A 25 18.20s user 0.04s system 99% cpu 18.257 total ^^ 3556K heap use. Strict in the elements, lazy in the spine: data Tree

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Tomasz Zielonka
On Mon, Dec 03, 2007 at 05:20:35AM +, PR Stanley wrote: Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any way.

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Don Stewart
dons: * Full strictness == teh suckness. * Mixed lazy and strict == flexible and efficient data types. Makes me wonder why Map is strict in the spine, data Map k a = Tip | Bin {-# UNPACK #-} !Size !k a !(Map k a) !(Map k a) Spencer points out that

Re: [Haskell-cafe] Possible Improvements

2007-12-02 Thread Derek Elkins
On Sun, 2007-12-02 at 21:54 -0800, Don Stewart wrote: catamorphism: On 12/2/07, Don Stewart [EMAIL PROTECTED] wrote: prstanley: Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs