Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fun with fixity

Tags:

haskell

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.

  1. I want # to be applied after ++. So does that mean the precedence should be higher or lower than ++? (++ is precedence 5.)

  2. 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...

like image 958
MathematicalOrchid Avatar asked Apr 17 '14 19:04

MathematicalOrchid


1 Answers

  1. $ 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 +.

  2. 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.

like image 130
David Young Avatar answered Nov 10 '22 19:11

David Young