gpt4 book ai didi

haskell - 冲突教程示例中 'pure' 关键字的用途是什么?

转载 作者:行者123 更新时间:2023-12-02 03:08:16 27 4
gpt4 key购买 nike

在Clash官方网站上,有以下示例:

>>> sampleN @System 4 (register 0 (pure (8 :: Signed 8)))

我知道什么是纯函数,但为什么这里有 this 关键字?如果我删除它,我会收到错误:

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 aSigned 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

关于haskell - 冲突教程示例中 'pure' 关键字的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407336/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com