想打印一个 0 到 10 之间的随机数,但生成似乎 undefined 无法编译,下面的代码从我使用 Haskell Platform 2011.2.0.1 的示例编辑
更新:
import System.IO
import System.Random
import Test.QuickCheck.Function
import Test.QuickCheck.Gen
import Test.QuickCheck
main :: IO()
main = putStrLn (show result)
where result = unGen (choose (0, 10)) (mkStdGen 1) 1
产生的错误:
test6.hs:13:25:
Ambiguous type variable `a0' in the constraints:
(Random a0) arising from a use of `choose' at test6.hs:13:25-30
(Show a0) arising from a use of `show' at test6.hs:12:18-21
(Num a0) arising from the literal `10' at test6.hs:13:36-37
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `unGen', namely `(choose (0, 10))'
In the expression: unGen (choose (0, 10)) (mkStdGen 1) 1
In an equation for `result':
result = unGen (choose (0, 10)) (mkStdGen 1) 1