The meaning of tilde in Haskell types (Type equality)

亡梦爱人 提交于 2019-11-28 02:55:24

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27667628/the-meaning-of-tilde-in-haskell-types-type-equality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!