OK, so here's a stupid question. I've defined a new #
operator, and I'm trying to figure out what the hell the fixity declaration should be.
I want #
to be applied after ++
. So does that mean the precedence should be higher or lower than ++
? (++
is precedence 5.)
The type is (#) :: Foo -> Bar -> Foo
. Do I want left-associative or right-associative? Because it appears to me that one of those will make x # y # z
type-check, and the other won't.
I know this might seem trivial, but I always always seem to get this wrong...
$
has the lowest precedence (0) and $
is always applied "last" so you want #
to have lower precedence than ++
. Also, you can compare the precedence of *
and +
.
Left associativity means that x # y # z = (x # y) # z
(this is how a left fold operates as well). x # (y # z)
would not type check but (x # y) # z
would, so you want it to be left associative.
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