我是Haskell的新手,正在尝试在一个紧凑的时间表上启动和运行一些代码,这就是为什么我要做一些比绝对基础知识更复杂的事情。我正在使用包newsynth,并且希望使用函数root_of_negative_one (documentation,source)。在GHCi中,我运行以下命令:
Prelude> import Quantum.Synthesis.Diophantine
Prelude Quantum.Synthesis.Diophantine> :set -package random
Prelude Quantum.Synthesis.Diophantine> import System.Random
Prelude Quantum.Synthesis.Diophantine System.Random> let g = getStdGen
Prelude Quantum.Synthesis.Diophantine System.Random> let x = root_of_negative_one g 5尝试得到-1 mod 5的平方根。GHCi返回:
<interactive>:7:9: error:
• No instance for (RandomGen (IO StdGen))
arising from a use of ‘root_of_negative_one’
• In the expression: root_of_negative_one g 5
In an equation for ‘x’: x = root_of_negative_one g 5我知道root_of_negative_one需要RandomGen类型的输入,但我似乎对RandomGen文档的理解还不够深入,无法执行此操作。任何帮助都是非常感谢的。谢谢!
发布于 2020-05-01 06:54:32
root_of_negative_one需要StdGen,但getStdGen是IO StdGen。您需要执行g <- getStdGen而不是let g = getStdGen。
https://stackoverflow.com/questions/61534032
复制相似问题