[wg-camlp4] Mix-fix notation

Wojciech Meyer wojciech.meyer at gmail.com
Tue Jan 29 22:50:40 GMT 2013

Dear list,

I'd like to take an opportunity to discuss possibility of a mix-fix
notation as a part of the core language.

For those who've never heard about mix-fix notation, it's a notation
belonging to class of light syntactical abstractions that allows to
encode bigger range of embedded DSLs than user defined infix operators
purely using usual functional abstractions - and not meta programming in
particular. Essentially, it's a super-class of infix operators where any
numbers of arguments denoted by special placeholders can be separated by
any number of tokens.

Mix-fix notation has successfully been used by some modern dependently
typed functional languages like Agda, or in some way is used to extend
the syntax in Coq via. Notation to implement for instance monads.

On this occasion, I'd like also discuss changes to the language
involving possibility of relaxing infix operators, and extending them
(like in Caml-light) with user defined precedence. With these
relaxations it might appear that the language will become more

Also, I'd like to focus on reusing mix-fix syntax to provide
meta-programming facilities - in particular defining new grammar entry
points using mix-fix.

So the mixfix notation in OCaml might look like this:

let _>>=_ m f = (* here a bind operator for a monad! *)

or if we are fancy for these technique in extending the syntax:

syntax _<--_-<_ pat e1 e2 = (* here is a code generator for an arrow! *)

Surely OCaml is strictly evaluated so all the usual tricks that can be
used in a language where evaluation strategy or order does not matter,
will not work, however it opens brand new doors for making combinator
based libraries. Also, it's very convenient and safe syntax for defining
grammar rules, instead of using BNF or even PEG and extending the
grammar by changing the rules in place.

I agree it would be a serious change to the language, therefore I
welcome an open discussion. Perhaps in extreme variant such change would
require writing a custom parser and lexer, and would render the OCaml
syntax incompatible, but having discussions about the quotations
mechanism, essentially embedding a DSL inside Caml, I'd like to shift
focus on safe and still expressive various applications of mix-fix and
possibility of providing such an abstraction to the OCaml world.

All the best,


More information about the wg-camlp4 mailing list