haskell - 冲突教程示例中“纯”关键字的用途是什么?
问题描述
在 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
有一个属于Applicative
which的实例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
推荐阅读
- javascript - 如何在 javascript 中对两个变量求和
- sql-server - 当列名是一行时连接表
- azure-devops - VSTS 项目的流程模板更改 - 需要注意的影响/要点
- javascript - 如何跟踪时间客户端和服务器端 PHP?
- git-lfs - 如何使用 GIT-LFS 重写 GIT 历史记录以跟踪整个目录
- spring - Rocket.chat 帐户登录/注册集成
- android - 我的项目和官方参考指南之间的不同功能签名
- javascript - TinyMCE:初始化后如何动态隐藏/显示工具栏按钮?
- reactjs - 启用组件特定的热重载?
- ibm-mq - 高并发应用程序的 JMSTemplate 和设置属性