在Haskell类型中的波浪符的含义(类型相等) [英] The meaning of tilde in Haskell types (Type equality)

查看:106
本文介绍了在Haskell类型中的波浪符的含义(类型相等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    > λlet fix f = let x = fx in x 
λfix(+)

< interactive>:15:5:
发生检查:不能构造无限类型:t〜t - > t
预期类型:t - > t
实际类型:t - > t - > t
在'fix'的第一个参数中,即'(+)'
在表达式中的相关绑定包括it :: t(在< interactive> 15:1处绑定) :fix(+)

我完全知道这个错误发生的原因,但我注意到一个有趣的类型那里的签名: t〜t - >吨。这种类型是什么意思? haskell中的类型签名是什么意思?他们在哪里使用?

解决方案

Tilde()意味着类型相等。它告诉你,它不能推导出 t t - >吨。该符号也用于 无可辩驳的模式 ,但这是完全不同的上下文。


I've been messing around with the fix function, and I happened across this:

λ let fix f = let x = f x in x
λ fix (+)

<interactive>:15:5:
    Occurs check: cannot construct the infinite type: t ~ t -> t
    Expected type: t -> t
      Actual type: t -> t -> t
    Relevant bindings include it :: t (bound at <interactive>:15:1)
    In the first argument of ‘fix’, namely ‘(+)’
    In the expression: fix (+)

I know full well why this error is occurring, but I noticed a funny type signature up there: t ~ t -> t. What does this type mean? What do tilde mean in type signatures within haskell? Where are they used?

解决方案

Tilde (~) in that error means type equality. It is telling you that it cannot deduce t to be t -> t. The symbol is also used for irrefutable patterns, but that's a completely different context.

这篇关于在Haskell类型中的波浪符的含义(类型相等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆