-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Datatype of thinnings #113
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ module Brat.Constructors.Patterns where | |
| import Brat.QualName | ||
|
|
||
| pattern CSucc, CDoub, CFull, CNil, CCons, CSome, CNone, CTrue, CFalse, CZero, CSnoc, | ||
| CConcatEqEven, CConcatEqOdd, CRiffle :: QualName | ||
| CConcatEqEven, CConcatEqOdd, CRiffle, COmit :: QualName | ||
| pattern CSucc = PrefixName [] "succ" | ||
| pattern CDoub = PrefixName [] "doub" | ||
| pattern CFull = PrefixName [] "full" | ||
|
|
@@ -18,8 +18,10 @@ pattern CSnoc = PrefixName [] "snoc" | |
| pattern CConcatEqEven = PrefixName [] "concatEqEven" | ||
| pattern CConcatEqOdd = PrefixName [] "concatEqOdd" | ||
| pattern CRiffle = PrefixName [] "riffle" | ||
| -- N.B. The opposite of `COmit` is `CSucc` | ||
| pattern COmit = PrefixName [] "omit" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhere round here (where COmit is declared) we should comment that the "opposite" of COmit is CSucc, i.e. nobody should go looking for CInclude |
||
|
|
||
| pattern CList, CVec, CNat, CInt, COption, CBool, CBit, CFloat, CString :: QualName | ||
| pattern CList, CVec, CNat, CInt, COption, CBool, CBit, CFloat, CString, CThin :: QualName | ||
| pattern CList = PrefixName [] "List" | ||
| pattern CVec = PrefixName [] "Vec" | ||
| pattern CNat = PrefixName [] "Nat" | ||
|
|
@@ -29,6 +31,7 @@ pattern CBool = PrefixName [] "Bool" | |
| pattern CBit = PrefixName [] "Bit" | ||
| pattern CFloat = PrefixName [] "Float" | ||
| pattern CString = PrefixName [] "String" | ||
| pattern CThin = PrefixName [] "Thin" | ||
|
|
||
| pattern CQubit, CMoney :: QualName | ||
| pattern CQubit = PrefixName [] "Qubit" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,35 @@ | ||
| --!xfail-parsing | ||
| -- Experiments with selecting out of vectors with first class selections | ||
| -- This feature has fallen by the wayside, so expect this to fail | ||
| select(X :: *, n :: #, m :: #, Thin(n, m), Vec(X, m)) -> Vec(X, n) | ||
| select(_, _, _, zero, []) = [] | ||
| select(_, _, _, succ(th), x ,- xs) = x ,- select(!, !, !, th, xs) | ||
| select(_, _, _, omit(th), _ ,- xs) = select(!, !, !, th, xs) | ||
|
|
||
| -- This type is WRONG | ||
| test :: Vec(X, 2) <<< Vec(X, 2) | ||
| test = {0..} -- The identity thinning | ||
| identity(n :: #) -> Thin(n, n) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok so we fix the parser failure by changing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a happy coincidence that these two functions lined up in the diff! |
||
| identity(0) = zero | ||
| identity(succ(_)) = succ(identity(!)) | ||
|
|
||
| test' :: Vec(X, 1) <<< Vec(X, 9) | ||
| test' = {5} -- just the fifth | ||
| empty(n :: #) -> Thin(0, n) | ||
| empty(0) = zero | ||
| empty(succ(_)) = omit(empty(!)) | ||
|
|
||
| vec :: Vec(Nat, 5) | ||
| vec = [1, 2, 3, 4, 5] | ||
|
|
||
| test'' :: Vec(Nat, 1) | ||
| test'' = vec{0} -- vec{2,4,5} | ||
| -- test''' :: Vec Nat 1 | ||
| -- test''' = <0> | ||
| comp(l :: #, n :: #, m :: #, Thin(l, n), Thin(n, m)) -> Thin(l, m) | ||
| comp(_, _, _, th, omit(ph)) = omit(comp(!, !, !, th, ph)) | ||
| comp(_, _, _, omit(th), succ(ph)) = omit(comp(!, !, !, th, ph)) | ||
| comp(_, _, _, succ(th), succ(ph)) = succ(comp(!, !, !, th, ph)) | ||
| comp(_, _, _, zero, zero) = zero | ||
|
|
||
| mapOn :: (th :: x <<< y), (f :: X -> X), Vec(X, y) -> Vec(X, y) | ||
| mapOn = ?mapOn | ||
| thinning1 :: Thin(3, 5) | ||
| thinning1 = succ(omit(succ(succ(omit(zero))))) | ||
|
|
||
| map = mapOn {1,4} f vec | ||
| thinning2 :: Thin(1, 3) | ||
| thinning2 = omit(succ(omit(zero))) | ||
|
|
||
| thinning :: Thin(1, 5) | ||
| thinning = comp(!, !, !, thinning2, thinning1) | ||
|
|
||
| --!exec [[1,3,4]] | ||
| go2 :: Vec(Nat, 3) | ||
| go2 = select(!, !, !, thinning1, [1,2,3,4,5]) | ||
|
|
||
| --!exec [[3]] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet! :) |
||
| go :: Vec(Nat, 1) | ||
| go = select(!, !, !, thinning, [1,2,3,4,5]) | ||
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.
I mean, I'm assuming we can't add the corresponding entry for
CReflhere