mirror of
https://github.com/anoma/juvix.git
synced 2025-01-06 06:53:33 +03:00
ef16b45ca6
- Closes #2188. This pr introduces a new syntactical statement for defining aliases: ``` syntax alias newName := oldName; ``` where `oldName` can be any name in the expression namespace. Fixity and module aliases are not supported at the moment. - The `newName` does not inherit the fixity of `oldName`. We have agreed that the goal is to inherit the fixity of `oldName` except if `newName` has a fixity statement, but this will be done in a separate pr as it requires #2310.
57 lines
928 B
Plaintext
57 lines
928 B
Plaintext
module Alias;
|
||
|
||
import Stdlib.Data.Fixity open;
|
||
|
||
-- aliases are allowed to forward reference
|
||
syntax alias Boolean := Bool;
|
||
syntax alias ⊥ := false;
|
||
syntax alias ⊤ := true;
|
||
|
||
--- Truth value
|
||
type Bool :=
|
||
| false
|
||
| true;
|
||
|
||
not : Boolean -> Boolean
|
||
| ⊥ := ⊤
|
||
| ⊤ := ⊥;
|
||
|
||
not2 (b : Boolean) : Boolean :=
|
||
let
|
||
syntax alias yes := ⊤;
|
||
syntax alias no := ⊥;
|
||
in case b
|
||
| no := yes
|
||
| yes := no;
|
||
|
||
module ExportAlias;
|
||
syntax alias Binary := Bool;
|
||
syntax alias one := ⊤;
|
||
syntax alias zero := ⊥;
|
||
end;
|
||
|
||
open ExportAlias;
|
||
|
||
syntax operator || logical;
|
||
|| : Binary -> Binary -> Binary
|
||
| zero b := b
|
||
| one _ := one;
|
||
|
||
syntax alias or := ||;
|
||
|
||
or3 (a b c : Binary) : Binary := or (or a b) c;
|
||
|
||
type Pair :=
|
||
| mkPair Binary Binary;
|
||
|
||
syntax operator , pair;
|
||
syntax alias , := mkPair;
|
||
|
||
myPair : Pair := one, ⊥;
|
||
|
||
localAlias : Binary -> Binary
|
||
| b :=
|
||
let
|
||
syntax alias b' := b;
|
||
in b';
|