冲突教程示例中 'pure' 关键字的用途是什么?
What is the purpose of 'pure' keyword in the clash tutorial example?
在Clash官网上,有如下例子:
>>> sampleN @System 4 (register 0 (pure (8 :: Signed 8)))
我知道什么是纯函数,但为什么要在这里使用这个关键字?如果我删除它,我会得到一个错误:
Clash.Prelude> sampleN @System 4 (register 0 (8 :: Signed 8))
<interactive>:2:32: error:
* Couldn't match expected type `Signal System a'
with actual type `Signed 8'
* In the second argument of `register', namely `(8 :: Signed 8)'
In the third argument of `sampleN', namely
`(register 0 (8 :: Signed 8))'
In the expression: sampleN @System 4 (register 0 (8 :: Signed 8))
* Relevant bindings include it :: [a] (bound at <interactive>:2:1)
有线索吗?
Signal
具有 pure
所属的 Applicative
实例。 pure :: a -> Signal dom a
将类型 Signed 8
的值提升为 Signal dom (Signed 8)
。在该上下文中与 Signal System a
结合导致 Signal System (Signed 8)
.
引用参考:http://hackage.haskell.org/package/clash-prelude-1.0.0/docs/Clash-Signal.html
在Clash官网上,有如下例子:
>>> sampleN @System 4 (register 0 (pure (8 :: Signed 8)))
我知道什么是纯函数,但为什么要在这里使用这个关键字?如果我删除它,我会得到一个错误:
Clash.Prelude> sampleN @System 4 (register 0 (8 :: Signed 8))
<interactive>:2:32: error:
* Couldn't match expected type `Signal System a'
with actual type `Signed 8'
* In the second argument of `register', namely `(8 :: Signed 8)'
In the third argument of `sampleN', namely
`(register 0 (8 :: Signed 8))'
In the expression: sampleN @System 4 (register 0 (8 :: Signed 8))
* Relevant bindings include it :: [a] (bound at <interactive>:2:1)
有线索吗?
Signal
具有 pure
所属的 Applicative
实例。 pure :: a -> Signal dom a
将类型 Signed 8
的值提升为 Signal dom (Signed 8)
。在该上下文中与 Signal System a
结合导致 Signal System (Signed 8)
.
引用参考:http://hackage.haskell.org/package/clash-prelude-1.0.0/docs/Clash-Signal.html