【发布时间】:2021-07-02 10:57:32
【问题描述】:
我正在关注 Wikipedia 上关于如何处理教会文字的指南。根据文章,有一个 Haskell sn-p:
维基链接Here
type Church a = (a -> a) -> a -> a
church :: Integer -> Church Integer
church 0 = \f -> \x -> x
church n = \f -> \x -> f (church (n-1) f x)
unchurch :: Church Integer -> Integer
unchurch cn = cn (+ 1) 0
但是,当我尝试通过 GHCI 运行它时,出现以下错误:
main.hs:3:15: error:
* Expecting one more argument to `Church'
Expected a type, but `Church' has kind `* -> *'
* In the first argument of `Show', namely `Church'
In the instance declaration for `Show Church'
|
3 | instance Show Church where
我尝试在类型上使用deriving show,并且还
instance Show Church Integer where
show = church
不幸的是,两者都产生了更多错误。我不确定 Church Integer 在函数声明中是什么意思,或者这是否是我无法派生 show 的部分原因?
如何让这个函数打印出来?
【问题讨论】:
-
试试
instance Show (Church Integer) where? -
你能添加教程的链接吗?我不确定我是否了解如何为函数构建 Show 实例。
-
@DimaKurilo 好点,编辑了 OT
-
好吧,本指南中似乎没有 Show 实例。而且您不能为类型定义它(没有语言扩展名)。所以很可能你想展示的不是教堂,而是(unchurch .church)5