Re: [Haskell-cafe] Haskell-cafe] Preventing sharing

Oleg rewrote my power-series one-liners to illustrate the fact that lazy lists defined in a strict language need not be very clumsy to use. I had implemented those funstions in many strict languages, one of which was ML using a lazy-list implementation from Dave MacQueen. But after I finally did it in Haskell, I never looked back. Though ML was the best of the strict bunch. Haskell's overloading and cleaner notation made for more perspicuous code. It also enabled elegant code like this for the exponential series: exps = 1 + integral exps As Oleg pointed out, this won't work in a strict language, and must be replaced with something much less vivid: exps = fix (\s 1 + integral s) In slightly more involved cases, such as sins = integral coss coss = 1 - integral sins the strict equivalent becomes murky: sins = fix (\s -> integral (1 - integral s)) coss = derivative sins or (sins, cosx) = fix (\sc -> (integral $ snd sc, 1 - integral $ fst sc) Further, because lazy lists are a new type, they can't be manipulated directly with the standard list vocabulary (map, take, filter, etc.). All such functions must be lifted to the new type. Thus, while lazy lists can be *programmed* in a strict language, they *play* somewhat awkwardly in it. In fairness, I must admit that the beauty of representation by naked lists may not survive when power series are embedded in a more comprehensive algebraic system. For example, if both matrices and power series were defined as list instances of Num, matrices might be confusEd with nested power series. Combinations--matrices of power series and vice versa--could be similarly ambiguous. But it could also turn out to cause no more difficulty than the already extensive degree of polymorphism in arithmetic expressions. Doug

On Fri, Jan 08, 2016 at 03:18:38PM -0500, Doug McIlroy wrote:
Though ML was the best of the strict bunch. Haskell's overloading and cleaner notation made for more perspicuous code. It also enabled elegant code like this for the exponential series:
exps = 1 + integral exps
As Oleg pointed out, this won't work in a strict language, and must be replaced with something much less vivid:
exps = fix (\s 1 + integral s)
Can you explain why the first line won't work for lazy lists in a strict language? It seems perfectly fine to me. Tom

On Fri, Jan 08, 2016 at 03:18:38PM -0500, Doug McIlroy wrote:
exps = 1 + integral exps
Can you explain why the first line won't work for lazy lists in a strict language? It seems perfectly fine to me.
Tom If I understand well the issue, simply because at the RHS exps is not a
Le 08/01/2016 21:33, Tom Ellis a écrit : thunk, it is evaluated, which breaks down the co-recursivity of the definition, even if the operators are delayed. In a strict language you would have to use a kind of macros to make it work. Good, old days... I believe I wrote a paper on lazy power series already in 1996 (but Douglas McI. hasn't read it). (Theoretical Computer Science 187, pp. 203–219, (1997).) I still have a copy: https://karczmarczuk.users.greyc.fr/Transport/power.pdf and I tried hard to do some Computer Algebra with that, trying to implement by force some lazy algorithms in a strict CA language MuPAD (similar to Maple, with strong OO structure). It was clumsy and almost nobody was convinced, when I presented this in Paderborn, the home of MuPAD. https://karczmarczuk.users.greyc.fr/Transport/paslid.pdf Then MuPad quit the free software world, got attached to MathWorks, and I simply forgot this experiment. I tried to convince some students to continue it using Mathematica (Hold, HoldRest, etc. permit to construct delayed lists; in general, a rewriting system seems better adapted to such kind of implementation, than purely procedural languages), but the results were ugly, and my dear students asked me to give them some other project... Jerzy Karczmarczuk

On Sat, Jan 09, 2016 at 12:24:23AM +0100, Jerzy Karczmarczuk wrote:
Le 08/01/2016 21:33, Tom Ellis a écrit :
On Fri, Jan 08, 2016 at 03:18:38PM -0500, Doug McIlroy wrote:
exps = 1 + integral exps
Can you explain why the first line won't work for lazy lists in a strict language? It seems perfectly fine to me.
If I understand well the issue, simply because at the RHS exps is not a thunk, it is evaluated, which breaks down the co-recursivity of the definition, even if the operators are delayed.
But if it evaluates to a thunk ...
participants (3)
-
Doug McIlroy
-
Jerzy Karczmarczuk
-
Tom Ellis