Glossing over some delicate points, 2 things that arose separately in Wombat turn out to be the same:
- We often want to combine procedures into one procedure. The procedures must agree for values where more than one succeed.
- The case statement passes the value to a sequence of procedures. These procedures typically start with a match statement which will succeed for relevant values. It returns the value from those procedures which succeed.
Well the case statement is exactly the same as calling the combined procedure.
The addition operator + is available for types that have the .conformsToMonoidAdd property. This property has to be compatible on the type hierarchy. For example Integer isa Rational, so Integer inherits Rational's .conformsToMonoidAdd property, so it is combined with its own, so they have to agree where both are defined, which is when both arguments are Integer. However we also use + for string concatenation since it is not overlapping with any other uses that it needs to be compatible with. It turns out we can also add procedures with combine. The identity is the unique procedure from Empty to Empty (that always fails).
We can write x|f to call f with input x (instead of f(x)). So now we don't need a case/switch operator. We just write:
value | ( procedure1 + procedure2 + ... )