
On 10 May 2004 00:02, JP Bernardy wrote:
What do you mean with this? Do you mean: "I think *I* was mistaken [...]"?
Huh, yes.
The current version behaves ok for sequences mainly constructed with fromList, cons or snoc; a sequence made up of 'append' is strict.
Would it be possible to change this behavior?
Sure. I attach the modified version, for reference.
Ross's point about requiring append to be strict in order to guarantee O(n) toList is a good one. In fact, the current implementation isn't quite correct: either fromList should be strict, or append should check for an empty Many constructor. Cheers, Simon

--- Simon Marlow
Ross's point about requiring append to be strict in order to guarantee O(n) toList is a good one. In fact, the current implementation isn't quite correct: either fromList should be strict, or append should check for an empty Many constructor.
That's what exists in the current published version (on my "web page"): fromList guarantees that the Many constructor never has [] as argument. Anyways, 'toList' will still be O(m) where m = number of subtrees. Moreover, I hardly expect more that O(n) empty subtrees in a sequence. So, it is trading off efficiency here for efficiency there. I suspect most haskellers would intuitively expect 'append' to be lazy, so I let myself be convinced by Wolfgang argument. Please let me know if I am wrong. Cheers, JP. __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover

Am Montag, 10. Mai 2004 15:56 schrieb JP Bernardy:
--- Simon Marlow
wrote: Ross's point about requiring append to be strict in order to guarantee O(n) toList is a good one. In fact, the current implementation isn't quite correct: either fromList should be strict, or append should check for an empty Many constructor.
That's what exists in the current published version (on my "web page"): fromList guarantees that the Many constructor never has [] as argument.
Is it right that making this guarantee results in the strictness I would like to avoid?
Anyways, 'toList' will still be O(m) where m = number of subtrees. Moreover, I hardly expect more that O(n) empty subtrees in a sequence.
It's theoretically possible that m is much larger than n. But since you need at least O(m) time to construct a Seq with m subtrees¹) the total time of Seq construction plus conversion is asymptotically the same as without full lazyness. __________ ¹) Well, exceptions could be cases like fix ([] `append`) which might be constructable in constant time.
[...]
Wolfgang

--- Wolfgang Jeltsch
Am Montag, 10. Mai 2004 15:56 schrieb JP Bernardy:
--- Simon Marlow
wrote: Ross's point about requiring append to be strict in order to guarantee O(n) toList is a good one. In fact, the current implementation isn't quite correct: either fromList should be strict, or append should check for an empty Many constructor.
That's what exists in the current published version (on my "web page"): fromList guarantees that the Many constructor never has [] as argument.
Is it right that making this guarantee results in the strictness I would like to avoid?
To be precise: Making fromList guarantee that "the Many constructor never has [] as argument" is a part of an implementation that gives the O(n) behaviour for toList. It does not make append strict. A strict append is necessary, in any case, for the O(n) behaviour.
Anyways, 'toList' will still be O(m) where m = number of subtrees. Moreover, I hardly expect more that O(n) empty subtrees in a sequence.
It's theoretically possible that m is much larger than n. But since you need at least O(m) time to construct a Seq with m subtrees�) the total time of Seq construction plus conversion is asymptotically the same as without full lazyness.
Yet, toList might be evaluated more than once for a given sequence. Cheers, JP. __________________________________ Do you Yahoo!? Win a $20,000 Career Makeover at Yahoo! HotJobs http://hotjobs.sweepstakes.yahoo.com/careermakeover

On Mon, 2004-05-10 at 12:46, Wolfgang Jeltsch wrote:
Anyways, 'toList' will still be O(m) where m = number of subtrees. Moreover, I hardly expect more that O(n) empty subtrees in a sequence.
It's theoretically possible that m is much larger than n. But since you need at least O(m) time to construct a Seq with m subtrees¹) the total time of Seq construction plus conversion is asymptotically the same as without full lazyness.
If we're talking about "theoretically possible": it's also possible that somebody converts to a list multiple times, or converts multiple subtrees to lists. Carl Witty
participants (4)
-
Carl Witty
-
JP Bernardy
-
Simon Marlow
-
Wolfgang Jeltsch