Re: coredump on innocent code
[email protected] Sat, 10 Sep 2005 15:18:16 -0000 (UTC)
| Newsgroups | gmane.comp.lang.haskell.hugs.bugs |
|---|---|
| Message-ID | <[email protected]> |
> On Thu, Sep 08, 2005 at 04:00:47PM +0000, [email protected] wrote: >> $ cat bug.hs >> main = print (let (x,(q,_)) = (1,divMod x x) in q) >> $ runhugs bug.hs >> Illegal instruction (core dumped) > > Not entirely innocent: demand for x also causes evaluation of the second > pair, which depends on x: an infinite loop. The correct version is > > main = print (let (x,~(q,_)) = (1,divMod x x) in q) This is a valuable clue. I previously thought that rewriting let <a> = <b> <c> = <d> in <e> as let (<a>,<c>) = (<b>,<d>) in <e> is harmless, but section 3.12 of the Report says different. I still don't understand why main = print (let (x,(q,_)) = (1,divMod x x) in q) and main = print (let (x,(q,_)) = (1,divmod x x) in q) divmod x y = (div x y,mod x y) behave differently. Please give me another clue. Thank you.