Hi I think this is a hugs bug. If I calculate Prelude> let g n = n^25 `mod` 18721 in g 4 I get 17173 But then if I calculate Prelude> let f n = snd( chr n, n^25 `mod` 18721 ) in f 4 I get 0 Which is different! I think the former is correct, FWIW. Replacing the "chr n" by something not involving chr and n gives 17173. This is with Hugs Version December 2001, running on a SunBlade 100 with Solaris 9. Gavin -- Gavin Lowe Oxford University Computing Laboratory, Parks Road, Oxford, OX1 3QD. Phone: +44 1865 273841. Fax: +44 1865 273839. E-mail: gavin.lowe@comlab.ox.ac.uk The secret of all discoverers is that they regard nothing as impossible
Gavin Lowe
I think this is a hugs bug.
It isn't. You will get the same behaviour in nhc98 and ghc.
Prelude> let g n = n^25 `mod` 18721 in g 4 17173
Prelude> let f n = snd( chr n, n^25 `mod` 18721 ) in f 4 0
The problem is with type-defaults for overloaded numbers. In the first example, n is inferred to be of type n :: Integral a => a which is defaulted to Integer. In the second example, because the type of chr is chr :: Int -> Char the type of n is inferred as Int, which cannot represent the value 4^25. Regards, Malcolm
I think I see what's going on. Prelude> :t f where f n = snd( chr n , n^25 `mod` 18721 ) let {...} in f :: Int -> Int Prelude> :t g where g n = n^25 `mod` 18721 let {...} in g :: Integral a => a -> a In the case of f, the use of chr forces n to be an Int, so it's calculating n^25 as an Int, which is 0 (because of arithmetic overflow). In the case of g, it's presumably using Integer, so gets the correct answer. Writing Prelude> let f n = snd( chr n , fromInt n^25 `mod` 18721 ) in f 4 gives the right answer. Gavin
From gavinl Mon Jan 6 15:34:20 2003 Date: Mon, 6 Jan 2003 15:34:19 GMT X-Authentication-Warning: client104.comlab: gavinl set sender to gavin.lowe@comlab.ox.ac.uk using -f From: Gavin Lowe
CC: Gavin.Lowe@comlab.ox.ac.uk Reply-to: gavin.lowe@comlab.ox.ac.uk Hi
I think this is a hugs bug.
If I calculate
Prelude> let g n = n^25 `mod` 18721 in g 4
I get
17173
But then if I calculate
Prelude> let f n = snd( chr n, n^25 `mod` 18721 ) in f 4
I get
0
Which is different! I think the former is correct, FWIW. Replacing the "chr n" by something not involving chr and n gives 17173.
This is with Hugs Version December 2001, running on a SunBlade 100 with Solaris 9.
Gavin
-- Gavin Lowe
Oxford University Computing Laboratory, Parks Road, Oxford, OX1 3QD. Phone: +44 1865 273841. Fax: +44 1865 273839. E-mail: gavin.lowe@comlab.ox.ac.uk
The secret of all discoverers is that they regard nothing as impossible
participants (2)
-
Gavin Lowe -
Malcolm Wallace