the-sett / elm-syntax-dsl

A DSL for creating Elm syntax trees and pretty printing Elm source code.
BSD 3-Clause "New" or "Revised" License
20 stars 4 forks source link

Better if the DSL already knows about operator associativity (and precedence). #8

Open rupertlssmith opened 5 years ago

rupertlssmith commented 5 years ago

The associativity of an operator must be given when using it:

opApply : String -> InfixDirection -> Expression -> Expression -> Expression

But it would not be hard to have the operator table in the DSL so it doesn't need to be told this, since the operators are fixed in number since Elm 0.19.

This would make a less clunky API:

opApply : String -> Expression -> Expression -> Expression
rupertlssmith commented 5 years ago

Another possibility might be to enumerate the operators:

Operator = 
     Times
   | Plus 
   | Minus
   | ...

so that it becomes impossible to create an operator that does not exist in Elm.

opApply : Operator -> Expression -> Expression -> Expression