haskell - Bizarre precedence and associativity -
looking through operator associativity , precedence found following:
infixr 0 $ infixl 1 & infixl 4 <$> infixl 1 <&> this seems bizarre. & , <&> have same precedence, $ , <$> not have different precedence, associate in different directions.
is there reason this, or historical wart? if it's historical wart, how go changing it?
i'm assuming <&> you're talking lens package. in case, lens operators set along other lens operators, , don't worry regular operators, <&> , & coincidence. other two, however, more thought out.
$ lowest precedence, definition. why exists; change order of text drastically can reduce need parentheses quite bit. it's naturally set @ 0. meanwhile, <$> application inside context, need do, opposed $ syntax help. <$> of higher precedence along other operators it, example alternative class operator <|> @ lower precedence calls can chained <$> appropriately.
as associativity, that's in how operators used. $ used simpler function composition. 1 might write f $ g $ x mean f (g x). whereas <$> chained <*>, infixl 4. way, statements following valid.
(+) <$> [1, 2, 3] <*> [10, 20, 30] that expression parse following, due left associativity.
((+) <$> [1, 2, 3]) <*> [10, 20, 30] which want. function (+) curried , accepts 2 parameters should passed in one-by-one. right associativity, following occur.
(+) <$> ([1, 2, 3] <*> [10, 20, 30]) this says apply of numbers in first list numbers in second list , add result to... something. needless say, not typecheck.
Comments
Post a Comment