【发布时间】:2017-03-20 06:12:27
【问题描述】:
我尝试了以下代码,但它会产生类型错误。
sa f = f f
• Occurs check: cannot construct the infinite type: t ~ t -> t1 • In the first argument of ‘f’, namely ‘f’ In the expression: f f In an equation for ‘sa’: sa f = f f • Relevant bindings include f :: t -> t1 (bound at fp-through-lambda-calculus-michaelson.hs:9:4) sa :: (t -> t1) -> t1 (bound at fp-through-lambda-calculus-michaelson.hs:9:1)
【问题讨论】:
-
你认为
sa应该有什么类型?请记住,Haskell 中的所有术语都必须具有类型。另外,你想解决什么问题? -
@Alec 我不知道,它需要一个可以带函数的函数?我只是在学习 lambda 演算,想知道如何在 Haskell 中表达它。我认为 Haskell 会很好地检查每个示例,但我立即陷入困境。也许 Lisp 或 Scheme 更容易达到这个目的。
-
这与您使用哪种语言无关。尝试在类型化的 lambda 演算中构造这个函数,并思考它应该有什么类型。我们会遇到类似的问题,不能构造无限类型
-
这很重要。您可以在 Lisp 和 Scheme 中轻松做到这一点,因为它们是动态类型的。