crb233 / unarian

Esoteric programming language based on unary functions.
MIT License
4 stars 0 forks source link

Definition of empty alternations #9

Closed DivergentClouds closed 1 year ago

DivergentClouds commented 1 year ago

README.md says

Finally, since there is no way to represent them syntactically, we don't define the behavior of empty alternations (although it seems logical to define an empty alternation as a function that fails on all input, since this is the identity element of function alternation).

however, it is possible to represent empty alternations syntactically as { | ... } where ... is any further code.

crb233 commented 1 year ago

By empty alternation, I mean an alternation expression with no arguments. So your example wouldn't count since it has two arguments ` and.... I think the only reason there's syntax for an empty composition is because I defined the empty expression to represent a composition with no arguments (extending the idea thata bcomposes two arguments anda` composes just one).

Semantically, the empty alternation should be something that behaves as the identity element of the alternation operator (analogously to an empty sum being 0 or an empty product being 1). This is another reason your example wouldn't work. The empty alternation must be a function F that fails on all inputs, since F | x = x and x | F = x for all x. It's possible construct F like this:

0 { - 0 | }
F { 0 - }

So F is semantically equivalent to an empty alternation, but I wouldn't call it an empty alternation because it's syntactically very different.

Thinking about this issue when I first wrote this part of the README led me to design an alternative syntax for Unarian which has an elegant syntax for empty alternations. In this alternative syntax, [ a b c ] represents the composition of a, b, c, and { a b c } represents the alternation of a, b, c. Then [ ] is the empty composition and { } is the empty alternation. Using this syntax, we can write the code above like this:

0 { [ - 0 ] [ ] }
F [ 0 - ]