Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
personoj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
koizel
personoj
Commits
b1e7a590
Commit
b1e7a590
authored
3 years ago
by
hondet
Browse files
Options
Downloads
Patches
Plain Diff
more on tuples
parent
a651edc5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
personoj/extra/arity-tools.lp
+1
-0
1 addition, 0 deletions
personoj/extra/arity-tools.lp
personoj/extra/tuple.lp
+26
-1
26 additions, 1 deletion
personoj/extra/tuple.lp
with
27 additions
and
1 deletion
personoj/extra/arity-tools.lp
+
1
−
0
View file @
b1e7a590
...
...
@@ -80,6 +80,7 @@ symbol car {n: N}: Vec n → Set;
rule car (cons $x _) ↪ $x;
symbol cdr {n: N}: Vec (s n) → Vec n;
rule cdr (cons _ $x) ↪ $x;
symbol cadr {n: N} (v: Vec (s n)): Set ≔ car (cdr v);
symbol nth {n: N}: N → Vec n → Set;
rule nth z (cons $x _) ↪ $x
...
...
This diff is collapsed.
Click to expand it.
personoj/extra/tuple.lp
+
26
−
1
View file @
b1e7a590
...
...
@@ -3,6 +3,7 @@ require open personoj.lhol;
require personoj.extra.arity-tools as A;
symbol +2 ≔ A.+ A.two;
symbol +3 ≔ A.+ A.three;
/* [σ {n} v] creates the tuple type of [n] + 2 elements. */
constant symbol σ {n: A.N}: A.Vec (+2 n) → Set;
...
...
@@ -12,6 +13,8 @@ constant symbol cons {n: A.N} {a: Set} {v: A.Vec (+2 n)}:
constant symbol double {a: Set} {b: Set}:
El a → El b → El (σ (A.vec A.two a b));
/* [nth n t] returns the [n]th element of tuple [t].
[nth 0 t ≡ car t] */
symbol nth {n: A.N} {v: A.Vec (+2 n)} (k: A.N): El (σ v) → El (A.nth k v);
rule @nth A.z _ A.z (double $x _) ↪ $x
with @nth A.z _ (A.s A.z) (double _ $y) ↪ $y
...
...
@@ -22,7 +25,9 @@ assert (x: Set) (e1 e2 e3: El x) ⊢ nth A.z (cons e1 (double e2 e3)) ≡ e1;
assert (x: Set) (e1 e2 e3: El x) ⊢ nth A.one (cons e1 (double e2 e3)) ≡ e2;
assert (x: Set) (e1 e2 e3: El x) ⊢ nth A.two (cons e1 (double e2 e3)) ≡ e3;
// [match f t] applies function [f] on each element of tuple [t]
/* [match f t] applies a function [f] on the elements of [t]. The arity of [f]
* is the number of elements of [t].
* [match (λ x y, x + y) (mkσ 1 2) ≡ 3] */
symbol match {n: A.N} {v: A.Vec (+2 n)} {r: Set}: El (A.vec->arr v r) → El (σ v) → El r;
rule match $f (cons $x $tl) ↪ match ($f $x) $tl
with match $f (double $x $y) ↪ $f $x $y;
...
...
@@ -72,3 +77,23 @@ with mkσ {A.s (A.s $n)} (A.cons $x (A.cons $y $tl)) $ex $ey ↪
rappend-mkσ {$n} {_} {$tl} {A.cons $y (A.cons $x A.nil)} (double {$y} {$x} $ey $ex);
assert (t: Set) (e1 e2 e3: El t) ⊢ mkσ (A.vec A.three t t t) e1 e2 e3 ≡ cons e1 (double e2 e3);
/// Low level accessors,
/// tuples are not supposed to be consed, they rather stand for fixed length
/// collections.
symbol car {n} {v: A.Vec (+2 n)} (t: El (σ v)) ≔ nth A.z t;
symbol cdr {n} {v: A.Vec (+3 n)} {a: Set}: El (σ (A.cons a v)) → El (σ v);
rule cdr (cons _ $x) ↪ $x;
symbol last {n: A.N} {v: A.Vec (+2 n)} (_: El (σ v)): El (A.nth (A.s n) v);
rule last (double _ $y) ↪ $y
with last (cons _ $y) ↪ last $y;
assert (a: Set) (x1 x2: El a) ⊢ car (double x1 x2) ≡ x1;
assert (a: Set) (x1 x2 x3: El a) ⊢ car (cons x1 (double x2 x3)) ≡ x1;
assert (a: Set) (x1 x2: El a) ⊢ last (double x1 x2) ≡ x2;
assert (a: Set) (x1 x2 x3: El a) ⊢ last (cons x1 (double x2 x3)) ≡ x3;
/* NOTE: the shortest tail that can be obtained through [cdr] is a [double]. To
get the last element of a tuple, [last] must be used. */
// Coercion: TODO
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment