We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent aa5ed5e commit 6e59931Copy full SHA for 6e59931
examples/DependentSafeHead.gr
@@ -0,0 +1,13 @@
1
+-- A dependent-type like example in Granule, using GADTs to capture a
2
+-- relation-like constraint, with an explicit proof witness
3
+data Vec (n : Nat) (a : Type) where
4
+ Nil : Vec 0 a;
5
+ Cons : forall {n : Nat} . a -> Vec n a -> Vec (n+1) a
6
+
7
+data UseOrNot (n : Nat) (k : Nat) where
8
+ Use : UseOrNot 0 1;
9
+ Not : forall {m : Nat} . UseOrNot (m+1) 0
10
11
+safeHead : forall {a : Type, n k : Nat} . Vec n a -> UseOrNot n k -> a [k] -> (a, Vec (n - 1) a)
12
+safeHead Nil Use [y] = (y, Nil);
13
+safeHead (Cons x xs) Not [_] = (x, xs)
0 commit comments