[Hugs-bugs] coredump on innocent code

fool at sdf-eu.org fool at sdf-eu.org
Sat Sep 10 11:18:16 EDT 2005


> On Thu, Sep 08, 2005 at 04:00:47PM +0000, fool at sdf-eu.org 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.




More information about the Hugs-Bugs mailing list