Skip to content

Instantly share code, notes, and snippets.

@Rufflewind
Last active October 4, 2015 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rufflewind/6316682cd738954474b3 to your computer and use it in GitHub Desktop.
Save Rufflewind/6316682cd738954474b3 to your computer and use it in GitHub Desktop.

Poset fixity declarations

Syntax

infix order p, q where
  tighter than a, b
  associate left c, d
  looser than e, f

infix order p, q where { tighter than a, b; associate left c, d; looser than e, f; }

infix order u -- no fixity at all; disconnected from all other operators

Multiple (non-conflicting) fixity declarations can occur in the same module, even for the same operators. (Allow duplicates?)

Restrictions

Conflicting declarations are disallowed:

  • Anything that directly introduces a cycle is obviously nonsense.
  • Anything that associates with other operators must associate in a consistent manner. (If c and d already associate right, then the example above is disallowed.)

Orphan declarations are disallowed: p and q must be defined in the current module. (Allow this to be turned off with a pragma?)

Order-inducing declarations are disallowed: this is to prevent cycles from occurred when two otherwise non-conflicting modules are used together. A fixity declaration is order-inducing if the declaration transitively induces an additional ordering between operators not defined in the current module. For example, if a and f are operators from another module and in those modules a binds neither tighter nor looser than f, then the fixity declaration above is disallowed as it would imply that a binds looser than f. This prevents the situation where another module transitively induces the opposite ordering, leading to a cycle. (Allow this to be turned off with a pragma?)

Compatibility

For compatibility with existing code, numeric fixity declarations are implicitly embedded into this ordering scheme by the compiler. The ordering for operators with numeric precedences is imposed on all other operators with a numeric precedence, including those not in the current scope and those that have not even been encountered by the compiler.

An operator is permitted to have both a numeric precedence and a poset fixity declaration as long as they do not conflict (again for backward compatibility).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment