grain icon indicating copy to clipboard operation
grain copied to clipboard

Parser disallows defining <<< as an operator

Open phated opened this issue 2 years ago • 3 comments

When trying to define the <<< operator in some code (below), the parser fails with this error:

Syntax error after '<<' and before '<'. Expected ) to complete the pattern.

let (<<<) = (p, q, state) => {
    let x = p(state)
    q(state): Void
    x
}

phated avatar Jun 10 '22 23:06 phated

It also disallows (|||)

phated avatar Jun 11 '22 05:06 phated

Unlike OCaml, Grain only supports operators defined by the language (pending documentation here: https://deploy-preview-301--grain-lang.netlify.app/docs/reference/lexical_structure/operators) and not arbitrary operators, so this is expected.

@phated are you suggesting we allow defining infix operators with a certain syntax? Here's what OCaml supports: https://caml.inria.fr/pub/docs/manual-caml-light/node4.9.html

ospencer avatar Jun 11 '22 22:06 ospencer

I think we should do something about allowing any combination of those characters in bindings. Even if it's only between parens. It's really weird/unexpected behavior that I can define bindings that overwrite internal operators, but can't use those characters in any other way.

phated avatar Jun 11 '22 23:06 phated