1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-06 06:53:33 +03:00
juvix/tests/positive/Alias.juvix
Jan Mas Rovira ef16b45ca6
Aliasing (#2301)
- 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.
2023-08-25 15:28:58 +02:00

57 lines
928 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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';