在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)
有任何线索吗?
答案 0 :(得分:4)
Signal
具有Applicative
所属的pure
的实例。 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