【发布时间】:2016-08-06 14:21:55
【问题描述】:
我正在尝试生成一些随机数和新的随机数生成器。我还没有走得太远,但是我遇到了这个错误,我不明白如何解决它。
我的代码是:
getGenerator :: RandomGen g => g
getGenerator = snd (next (mkStdGen 42))
我得到的错误是:
Couldn't match expected type ‘g’ with actual type ‘StdGen’
‘g’ is a rigid type variable bound by
the type signature
有人可以解释我做错了什么吗?我也尝试将 RandomGen 切换到 StdGen 但得到错误:
‘StdGen’ is applied to too many type arguments
我看到 mkStdGen 创建了一个 StdGen,但根据 wiki 页面,StdGen 是 RandomGen 的一个实例。有没有办法以某种方式将 StdGen 转换为 RandomGen?我现在真的很困惑。
【问题讨论】:
标签: haskell functional-programming