The following snippet compiles:
{-# LANGUAGE TypeFamilies #-}
type family Foo a b
f :: (Foo a b ~ Int) => a -> b -> b
f = error ""
but infix type operators seem to behave differently:
{-# LANGUAGE TypeFamilies #-}
type family a \\ b
f :: (a \\ b ~ Int) => a -> b -> b
f = error ""
GHC complains that the second argument to \\
should have kind *
, but b ~ Int
has kind Constraint
. Of course this can be fixed with parens, but I'm wondering if there's another way.
I've tried setting the precedence of my operator with the fixity declaration infixl 9 \\
, but that doesn't fix the problem, indicating that the precedence of ~
is at least 9 (if I'm interpreting that correctly). I tried using the trick from this answer to make GHCi tell me the precedence of ~
, but it didn't work.
Technically speaking, ~
probably isn't a type operator, it's more of a lexical construct similar to ,
, but the questions still stand:
- Why do infix and prefix operators exhibit different behavior?
- Why does
~
bind so tightly? - Is there something I can do to make my own operators bind even tighter?
(Note: This question asks about the precedence of type functions, but it doesn't say anything about ~
.)