Design Choice - Glow-Lang/glow GitHub Wiki

How best may we express choice, wherein one of many different kinds of events can happen, sent by one of many kinds of participants?

NB: For the economic considerations involved in implementing such choice, see also Incentives.

Here are a few possibilities for choice syntax:

  • Imperative style, that I'd strongly like to avoid: switch (getEvent()) { ... }
  • Pattern matching style: choice { | eventPattern1 => ... | eventPattern2 => ...}
  • choice (eventPattern) { ... }
  • something else entirely?

What would the pattern language be?

  • Can we make patterns symmetrical with the publish! and deposit! actions? Maybe we need to refactor the language to achieve symmetry?
  • How do we ensure that the patterns are easily structurally discriminated between? Do we require the user to define and use a nominal sum type, or do we automatically generate a (extensible?) structural sum type? Do we put the structural discrimination in the pattern, or out of it (e.g. automatically add a implicit number so the user tells which pattern he chose)? In the latter case, how do express an explicit choice in the client-specific user interface?