冲突教程示例中的“ pure”关键字的作用是什么?

时间:2019-10-16 06:51:31

标签: haskell hdl clash

在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)

有任何线索吗?

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