-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release-v0.4.0: Bump version and update changelog Add documentation for sections and variables Make implicit use of variables an error Check that "used" vars are defined and used Fix warning in recId example Add "uses(...)" annotation Add anonymous sections Issue a warning for implicit assumptions Issue an error for unused variables Correctly collect free variables for a typed term Change recId example to use sections and variables Add Coq-style sections and variables add flake with cabal, hls, ghcjs, set up caching Apply stylish-haskell
- Loading branch information
Showing
32 changed files
with
7,992 additions
and
6,718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
use flake | ||
eval "$shellHook" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,35 @@ on: | |
|
||
workflow_dispatch: # allow triggering this workflow manually | ||
|
||
env: | ||
store: /home/runner/nix | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 📥 Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: 🧰 Setup nix (cache) | ||
uses: cachix/install-nix-action@v13 | ||
- name: 🧰 Setup nix | ||
uses: cachix/install-nix-action@v20 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
nix_path: nixpkgs=channel:nixpkgs-unstable | ||
extra_nix_config: "store = ${{ env.store }}\nsubstituters = https://cache.nixos.org/ https://cache.iog.io https://nix-community.cachix.org https://miso-haskell.cachix.org \ntrusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= miso-haskell.cachix.org-1:6N2DooyFlZOHUfJtAx1Q09H0P5XXYzoxxQYiwn6W1e8=" | ||
# pinning Nix version | ||
install_url: https://releases.nixos.org/nix/nix-2.13.3/install | ||
|
||
- name: 💾 Setup cachix (miso-haskell) | ||
uses: cachix/cachix-action@v10 | ||
install_url: https://releases.nixos.org/nix/nix-2.14.1/install | ||
- name: Restore and cache Nix store | ||
uses: actions/[email protected] | ||
with: | ||
name: miso-haskell | ||
key: ${{ runner.os }}-nix-${{ hashfiles('./flake.nix', './flake.lock') }} | ||
path: ${{ env.store }} | ||
restore-keys: | | ||
${{ runner.os }}-nix-${{ hashfiles('./flake.nix', './flake.lock') }} | ||
${{ runner.os }}-nix- | ||
- name: 🔨 Remove rzk.cabal, lexer and parser generator files | ||
run: | | ||
|
@@ -45,20 +56,20 @@ jobs: | |
- name: 🔨 Build GHCJS version with Nix | ||
run: | | ||
nix-build try-rzk/ | ||
nix build .#try-rzk | ||
- name: 🔨 Collect build artifacts | ||
run: | | ||
mkdir -p dist/result/bin | ||
cp -r ./result/bin/try-rzk.jsexe/ dist/result/bin/. | ||
cp -r ${{ env.store }}$(realpath result)/bin/try-rzk.jsexe/ dist/result/bin/. | ||
chmod -R +w dist/ | ||
cp try-rzk/playground.html dist/. | ||
- name: "📘 Publish JS \"binaries\" (${{ github.ref_name }})" | ||
if: ${{ github.ref_name != 'main' && github.event_name == 'push' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
folder: dist | ||
target-folder: ${{ github.ref_name }} | ||
clean: false | ||
|
@@ -67,6 +78,6 @@ jobs: | |
if: ${{ github.ref_name == 'main' && github.event_name == 'push' }} | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
folder: dist | ||
clean: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ cabal.project.local~ | |
.HTF/ | ||
.ghc.environment.* | ||
docs/site | ||
result | ||
.direnv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: rzk try-rzk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Sections and Variables | ||
|
||
Sections and variables allow to simplify definitions by factoring out common assumptions. | ||
|
||
!!! hint "Coq-style variables" | ||
`rzk` implements variables similarly to | ||
<a href="https://coq.inria.fr/refman/language/core/assumptions.html#coq:cmd.Variable" target="_blank">`Variable` command in Coq</a>. | ||
An important difference is that `rzk` does not allow definitions to use variables implicitly and adds `uses (...)` annotations to ensure such dependencies are not accidental. | ||
This is, perhaps, somewhat related to <a href="https://coq.inria.fr/refman/proofs/writing-proofs/equality.html#coq:exn.Section-variable-‘ident’-occurs-implicitly-in-global-declaration-‘qualid’-present-in-hypothesis-‘ident’" target="_blank">this error message in Coq</a>. | ||
|
||
This is a literate `rzk` file: | ||
|
||
```rzk | ||
#lang rzk-1 | ||
``` | ||
|
||
## Variables | ||
|
||
Consider the following definitions: | ||
|
||
```rzk | ||
#def compose₁ | ||
(A B C : U) | ||
(g : B -> C) | ||
(f : A -> B) | ||
: A -> C | ||
:= \x -> g (f x) | ||
#def twice₁ | ||
(A : U) | ||
(h : A -> A) | ||
: A -> A | ||
:= \x -> h (h x) | ||
``` | ||
|
||
Since it might be common to introduce types `A`, `B`, and `C`, we can declare these are variables: | ||
|
||
```rzk | ||
#variables A B C : U | ||
#def compose₂ | ||
(g : B -> C) | ||
(f : A -> B) | ||
: A -> C | ||
:= \x -> g (f x) | ||
#def twice₂ | ||
(h : A -> A) | ||
: A -> A | ||
:= \x -> h (h x) | ||
``` | ||
|
||
The `#variables` command here introduces assumptions, which can be used in the following definitions. Importantly, after checking a file (module), all definitions will have the assumptions used (explicitly or implicitly) attached as bound variables. | ||
|
||
### Implicitly used variables (and `uses`) | ||
|
||
We can try going even further and declare variables `f`, `g`, `h`, and `x`: | ||
|
||
```rzk | ||
#variable g : B -> C | ||
#variable f : A -> B | ||
#variable h : A -> A | ||
#variable x : A | ||
-- #def bad-compose₃ : C := g (f x) -- ERROR: implicit assumptions A and B | ||
#def twice₃ : A := h (h x) | ||
``` | ||
|
||
Note how this definition of `bad-compose₃` is implicitly dependent on the types `A` and `B`, which is promptly noted by `rzk`, which issues an error (if we uncomment the corresponding line): | ||
|
||
```text | ||
implicit assumption | ||
B : U | ||
used in definition of | ||
bad-compose₃ | ||
``` | ||
|
||
To let `rzk` know that this is not accidental, we can add `uses (...)` annotation to specify a list of variables implicitly used in the definition: | ||
|
||
```rzk | ||
#def compose₃ uses (A B) : C := g (f x) | ||
``` | ||
|
||
## Sections | ||
|
||
To introduce assumption variables temporarily inside of one file, you can use sections: | ||
|
||
```rzk | ||
#section example-1 | ||
#variables X Y Z : U | ||
#variable k : X -> X | ||
#variable x' : X | ||
#def compose₄ | ||
(g : Y -> Z) | ||
(f : X -> Y) | ||
: X -> Z | ||
:= \x -> g (f x) | ||
#def twice₄ : X := k (k x') | ||
#end example-1 | ||
``` | ||
|
||
Now, once outside of the section, `compose₄` and `twice₄` obtain corresponding parameters | ||
(only those used, explicitly or implicitly): | ||
|
||
```rzk | ||
-- compose₄ : (X : U) -> (Y : U) -> (Z : U) -> (g : Y -> Z) -> (f : X -> Y) -> (X -> Z) | ||
-- twice₄ : (X : U) -> (k : X -> X) -> (x' : X) -> X | ||
#def twice₅ | ||
(T : U) | ||
(e : T -> T) | ||
: T -> T | ||
:= compose₄ T T T e e | ||
#def identity | ||
(T : U) | ||
: T -> T | ||
:= twice₄ T (\t -> t) | ||
``` | ||
|
||
!!! warning "Lack of indentation" | ||
`rzk` currently does not support indentation, so all definitions and commands inside a section (including nested sections) have to start at the beginning of a line. |
Oops, something went wrong.