随机生成器如何在榆树中工作?
How does the Random generator work in elm?
我无法理解随机生成器的工作原理。
在下面的例子中,我试图在点击时掷两个骰子,
https://ellie-app.com/d9rXQHpfJa1/1
但我正在
Function generate is expecting the 2nd argument to be:
Random.Generator ( Int, Int )
But it is:
( Random.Generator Int, Random.Generator Int )
该错误消息强烈暗示您正试图传递一个不符合预期的参数。 Elm 做了很多类型推断,因为 NewFace (Int, Int)
是一个接受两个整数的元组的构造函数,这就是它对传递给 generate
.
的第二个参数的期望
如果您访问 Random package documentation, you'll see a function that takes two generators and gives you back a generator that uses the first two in a tuple. It is called Random.pair
,并且在您的代码中使用它,它看起来像这样:
( model, Random.generate NewFace (Random.pair (Random.int 1 6) (Random.int 1 6 )))
我无法理解随机生成器的工作原理。
但我正在
Function generate is expecting the 2nd argument to be:
Random.Generator ( Int, Int )
But it is:
( Random.Generator Int, Random.Generator Int )
该错误消息强烈暗示您正试图传递一个不符合预期的参数。 Elm 做了很多类型推断,因为 NewFace (Int, Int)
是一个接受两个整数的元组的构造函数,这就是它对传递给 generate
.
如果您访问 Random package documentation, you'll see a function that takes two generators and gives you back a generator that uses the first two in a tuple. It is called Random.pair
,并且在您的代码中使用它,它看起来像这样:
( model, Random.generate NewFace (Random.pair (Random.int 1 6) (Random.int 1 6 )))