hackett icon indicating copy to clipboard operation
hackett copied to clipboard

Precedence for infix operators

Open AnthonyJacob opened this issue 8 years ago • 4 comments

Is it possible implement Haskell syntax for infix operators?

Example :

(infixr 4 +)

(1 + 2)

In this sense (infixr 4 +) is just a shorthand macro definition that gets globally applied to all expressions.

AnthonyJacob avatar Jan 04 '17 07:01 AnthonyJacob

Infix operators are planned, in some way or another. The exact details are not squared away yet. However, you will need to use { curly braces } to enter “infix mode”, since there won’t be a syntactic distinction between infix operators and prefix operators like Haskell has (based on characters in identifiers). You will be able to assign associativity and precedence, though.

lexi-lambda avatar Jan 04 '17 12:01 lexi-lambda

Could you elaborate why there will be no distinction between prefix and infix?

AnthonyJacob avatar Jan 08 '17 06:01 AnthonyJacob

I would like to avoid assigning meaning to the names of identifiers. Lisp identifiers are traditionally much more lax about which characters you can use in an identifier, so you can name an identifier do-it! if you want, or even a!b@c#d$. This also avoids needing a syntax for converting prefix operators to infix ones and vice versa, since the (<>) and `elem` syntaxes wouldn’t work so well in a Lisp.

lexi-lambda avatar Jan 08 '17 15:01 lexi-lambda

Associativity is now implemented in the new implementation in e7767ad0ecbb5ccafef3adb2c15ee8f04d0e31c5, but precedence is still unimplemented. You can now specify associativity when writing a definition by writing #:fixity left or #:fixity right. left is the default.

This means type signatures can get a bit cleaner, since -> is now properly right-associative. You can now write {Integer -> Integer -> Integer}, and it will parse the way you would expect.

lexi-lambda avatar May 24 '17 08:05 lexi-lambda