-
Notifications
You must be signed in to change notification settings - Fork 15
Add initial redex implementation of Qi #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,11 @@ | ||
| #lang info | ||
|
|
||
| (define version "5.0") | ||
| (define collection "qi") | ||
| (define deps '("base" | ||
| "redex-lib")) | ||
| (define build-deps '()) | ||
| (define clean '("compiled" "private/compiled")) | ||
| (define compile-omit-paths '("tests")) | ||
| (define test-include-paths '("tests")) | ||
| (define pkg-authors '(countvajhula)) | ||
This file contains hidden or 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,146 @@ | ||
| #lang racket/base | ||
|
|
||
| (require redex/reduction-semantics) | ||
|
|
||
| (provide Qi floe-reduce) | ||
|
|
||
| (define-language Qi | ||
| ;; Variables | ||
| (x ::= variable-not-otherwise-mentioned) | ||
| (n ::= number) | ||
| ;; Lambda calculus / Racket expressions | ||
| (e ::= (λ (x ...) e) (e e ...) x n (values e ...)) | ||
| ;; Lambda calculus contexts | ||
| (E ::= hole (v ... E e ...) (values v ... E e ...)) | ||
| ;; Normalised terms / Racket values | ||
| (v ::= (λ (x ...) e) n) | ||
| ;; Flow expressions | ||
| (f ::= | ||
| (~> f ...) | ||
| (-< f ...) | ||
| (== f ...) | ||
| (gen e ...) | ||
| (esc e) | ||
| (>< f)) | ||
| ;; Flow values (normalised flows) | ||
| (fv ::= (gen v ...)) | ||
| ;; Flow contexts | ||
| (F ::= hole | ||
| (~> fv ... F f ...) | ||
| (-< fv ... F f ...) | ||
| (== fv ... F f ...) | ||
| (gen v ... E e ...) | ||
| (esc E) | ||
| (>< F)) | ||
|
|
||
| #:binding-forms | ||
| (λ (x ...) e #:refers-to (shadow x ...))) | ||
|
|
||
| (define-metafunction Qi | ||
| β-reduce : (λ (x ..._1) e) e ..._1 -> e | ||
| [(β-reduce (λ (x ...) e) e_x ...) (substitute e [x e_x] ...)]) | ||
|
|
||
| ;; Floe reductions | ||
| (define floe-reduce | ||
| (reduction-relation | ||
| Qi | ||
| ;; Threading | ||
| (--> (in-hole F (~> (gen v ...) (esc v_1) f ...)) | ||
| (in-hole F (~> (gen (v_1 v ...)) f ...)) | ||
| thread-step) | ||
| (--> (in-hole F (~> (gen v ...))) | ||
| (in-hole F (gen v ...)) | ||
| thread-red) | ||
| ;; Tee | ||
| (--> (in-hole F (~> (gen v ...) (-< f ...))) | ||
| (in-hole F (-< (~> (gen v ...) f) ...)) | ||
| tee-step) | ||
| (--> (in-hole F (-< (gen v ...) ...)) | ||
| (in-hole F (gen v ... ...)) | ||
| tee-red) | ||
| ;; Relay | ||
| (--> (in-hole F (~> (gen v ...) (== f ...))) | ||
| (in-hole F (-< (~> (gen v) f) ...)) | ||
| relay-red) | ||
| ;; Amp | ||
| (--> (in-hole F (~> (gen v ...) (>< f))) | ||
| (in-hole F (-< (~> (gen v) f) ...)) | ||
| amp-red) | ||
| ;; Gen | ||
| (--> (in-hole F (gen v_1 ... (values v_2 ...) e ...)) | ||
| (in-hole F (gen v_1 ... v_2 ... e ...)) | ||
| gen-values) | ||
| (--> (in-hole F (~> (gen v_1 ...) (gen v_2 ...))) | ||
| (in-hole F (gen v_2 ...)) | ||
| gen-red) | ||
|
|
||
| ;; Lambda calculus reductions | ||
| (--> (in-hole F ((λ (x ...) e) v ...)) | ||
| (in-hole F (mf-apply β-reduce (λ (x ...) e) v ...)) | ||
| beta-red))) | ||
|
|
||
| (module+ test | ||
| (test--> | ||
| floe-reduce | ||
| (term (~> (gen 0))) | ||
| (term (gen 0))) | ||
|
|
||
| (test--> | ||
| floe-reduce | ||
| (term (~> (~> (gen 0)))) | ||
| (term (~> (gen 0)))) | ||
|
|
||
| (test-match Qi f (term (esc (λ (x) x)))) | ||
| (test-match Qi fv (term (gen 1))) | ||
|
|
||
| (test--> | ||
| floe-reduce | ||
| (term (~> (gen 1) (esc (λ (x) x)))) | ||
| (term (~> (gen ((λ (x) x) 1))))) | ||
|
|
||
| (test--> | ||
| floe-reduce | ||
| (term (gen ((λ (x) x) 1))) | ||
| (term (gen 1))) | ||
|
|
||
| (test-->> | ||
| floe-reduce | ||
| (term (~> (gen 1) (esc (λ (x) x)))) | ||
| (term (gen 1))) | ||
|
|
||
| (test--> | ||
| floe-reduce | ||
| (term (gen (values 1 2 3))) | ||
| (term (gen 1 2 3))) | ||
|
|
||
| (test-->> | ||
| floe-reduce | ||
| (term (~> (gen 1 2) | ||
| (-< (esc (λ (x y) y)) | ||
| (esc (λ (x y) x))))) | ||
| (term (gen 2 1))) | ||
|
|
||
| (test-->> | ||
| floe-reduce | ||
| (term (~> (gen 1 2) | ||
| (-< (esc (λ (x y) (values x y))) | ||
| (esc (λ (x y) (values y x)))))) | ||
| (term (gen 1 2 2 1))) | ||
|
|
||
| (test-->> | ||
| floe-reduce | ||
| (term (~> (gen 1 2) | ||
| (== (esc (λ (x) (values 0 x))) | ||
| (esc (λ (x) (values x 3)))))) | ||
| (term (gen 0 1 2 3))) | ||
|
|
||
| (test-->> | ||
| floe-reduce | ||
| (term (~> (gen 1 2) | ||
| (>< (esc (λ (x) (values x 0)))))) | ||
| (term (gen 1 0 2 0))) | ||
|
|
||
| (test--> | ||
| floe-reduce | ||
| (term (~> (gen 1 2 3) (gen 4))) | ||
| (term (gen 4)))) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to have any name here, might as well be
eutro!