0
想打印一個介於0和10之間的隨機數,但生成似乎未定義 無法編譯,下面的代碼從示例 編輯了我正在使用Haskell Platform 2011.2.0.1函數在Haskell平臺中生成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
變化mkStdGen到MkGen,不能編譯 –
@種瓜得瓜種豆得豆你真的需要一個'StdGen'對象。不支持其他隨機生成器的使用。 – fuz
mkStdGen現在可以使用,但上面不能編譯 –