Haskell's random

Hi, it is NISHIO Hirokazu, Haskell newbie. Today I post a small code. It's not a bug. It's a feature of Haskell.

$ ghci
GHCi, version 6.8.3
Prelude> import Random
Prelude Random> let g = mkStdGen 1
Prelude Random> (fst (random g)) + 0
Prelude Random> (fst (random g)) / 1
Prelude Random> (fst (random g)) * 1
Prelude Random> (fst (random g)) * 1.0

Yes, it is a feature. Haskell's random changes its behavior by what type inferred. See The Haskell 98 Library Report: Random Numbers.

No comments: