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:
~
bind so tightly?(Note: This question asks about the precedence of type functions, but it doesn't say anything about ~
.)
What Does Precedence Mean? Precedence, in C#, is the rule that specifies the order in which certain operations need to be performed in an expression. For a given expression containing more than two operators, it determines which operations should be calculated first.
It stands for Parentheses, Exponents, Multiplication/Division, Addition/Subtraction. PEMDAS is often expanded to the mnemonic "Please Excuse My Dear Aunt Sally" in schools.
When there is more than one arithmetic operator in an expression; multiplication, division, and modulo are calculated first, followed by subtraction and addition. If all arithmetic operators in an expression have the same level of precedence, the order of execution is left to right.
1) What is the Priority among (*, /, %), (+, -) and (=) C Operators.? Explanation: Assignment operator in C has the least priority.
~
isn't an operator, it's a keyword, like module
or case
, so I think you could only alter the precedence using parentheses.
See more here: https://wiki.haskell.org/Keywords#.7E
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With