MinHugs-Sep2006.exe does wrong Integer arithmetic

rolle at hush.ai rolle at hush.ai
Wed Dec 29 04:10:32 CET 2010


(Re-sending.  Does this list drop mail from non-subscribers?)

I've seen the hugs distribution that is hosted as
http://ndmitchell.googlecode.com/files/MinHugs-Sep2006.exe
and has the SHA1 checksum 02f62efe00334007eb7083d09bae6e692a48c7c2
evaluate the script below incorrectly on two different Windows XP
computers.

The correct output is [], but I get a non-empty list.  On one 
computer
I get different output for successive runs of the same script
(restarting hugs) by saying "main".  On the other one I get 
different
output by saying "main" versus "ls".

I can't reproduce the problem on two different UNIX-like systems 
with
the September 2006 version of hugs.  The problem goes away by 
replacing
"Integer" with "Int".


type Z = Integer

qs :: Z -> Z
qs 0 = 0
qs x = let (q,r) = divMod x 10 in r + qs q

iqs :: Z -> Z
iqs x = if x < 10 then x else iqs (qs x)

ok :: Z -> Z -> Bool
ok x y = iqs (iqs x * iqs y) == iqs (x*y)

n :: Z
n = 1000

ls :: [(Z,Z)]
ls = [(x,y) | x<-[1..n], y<-[x..n], not (ok x y)]

main = print ls




More information about the Hugs-Bugs mailing list