3 ms·
Haskell lets you express that types unify: `a ~ b` says that `a` unifies with `b`, and similarly `Int ~ b` or `Bool ~ Char` (though the last one is clearly fals
by ivanbakel 7y ago
Haskell lets you express that types unify: `a ~ b` says that `a` unifies with `b`, and similarly `Int ~ b` or `Bool ~ Char` (though the last one is clearly false).
But there's no equivalent for non-unification - `a /~ b`. You can sort of hack it by asking the compiler "do these types unify right now", and then negating the response you get, but that doesn't work for types which eventually unify, but just fail to at the moment.
A good example is with non-injective type functions. To show `Maybe a ~ Maybe b`, you can exploit the fact that `Maybe` is an injective type constructor to simplify the problem to deciding if `a ~ b`. But if you have an ad-hoc type function which is not injective, say `Foo`, then it's possible that `Foo a ~ Foo b` even if `a /~ b`. It's worse if you have two different type functions - `Foo a ~ Bar b`. Those types fail to unify immediately because `Foo` is definitely different to `Bar` - but depending on the final values of `a` and `b`, the types they result in may unify.
- philzook 7y agoYou can achieve a certain amount of type disequality in Haskell. It isn't necessarily easy or sufficient for all purposes. There is a type family that returns a type level Bool for equality here. https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Type-Equality.html https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-... There are some older techniques here http://okmij.org/ftp/Haskell/typeEQ.html http://okmij.org/ftp/Haskell/typeEQ.html
- Tarean 7y agoYou can do `(A == B)~ False` but that won't affect type variable unification. Pretty sure `/~` would break type class coherence under haskell's open world assumption?