Skip to content

Commit

Permalink
merge: More things in the lib, handle empty patterns (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 authored Jun 4, 2024
2 parents 31b99ba + 9eb394c commit d6624a9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cli-impl/src/test/resources/shared/src/arith/nat.aya
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public open import arith::nat::base
public open import arith::nat::properties
12 changes: 10 additions & 2 deletions cli-impl/src/test/resources/shared/src/arith/nat/base.aya
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@ open import paths

open inductive Nat | zero | suc Nat

variable a b c : Nat

overlap def infixl + Nat Nat : Nat
| 0, b => b
| a, 0 => a
| suc a, b => suc (a + b)
| a, suc b => suc (a + b)
tighter =

overlap def +-comm {a b : Nat} : a + b = b + a elim a b
overlap def +-comm : a + b = b + a elim a b
| 0, _ => refl
| suc _, _ => pmap suc +-comm
| _, 0 => refl
| _, suc _ => pmap suc +-comm

overlap def +-assoc {a b c : Nat} : a + (b + c) = (a + b) + c elim a b c
overlap def +-assoc : a + (b + c) = (a + b) + c elim a b c
| 0, _, _ => refl
| _, 0, _ => refl
| _, _, 0 => refl
| suc _, _, _ => pmap suc +-assoc
| _, suc _, _ => pmap suc +-assoc
| _, _, suc _ => pmap suc +-assoc

overlap def infixl * Nat Nat : Nat
| 0, n => 0
| m, 0 => 0
| suc m, n => n + m * n
tighter +
16 changes: 16 additions & 0 deletions cli-impl/src/test/resources/shared/src/arith/nat/properties.aya
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open import arith::nat::base
open import data::empty
open import paths

private def diag Nat : Type
| 0 => Nat
| suc a => Empty

def z≠s {a : Nat} (p : 0 = suc a) : Empty => coe 0 1 (\i => diag (p i)) a

private def suc-inj Nat : Nat
| 0 => 114514
| suc m => m

def s=s {m n : Nat} (p : suc m = suc n) : m = n => (\i => suc-inj (p i))

4 changes: 4 additions & 0 deletions cli-impl/src/test/resources/shared/src/data/empty.aya
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inductive Empty
variable A : Type

def exfalso Empty : A | ()
18 changes: 17 additions & 1 deletion cli-impl/src/test/resources/shared/src/data/list/base.aya
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open inductive List (A : Type)
| nil
| infixr :< A (List A) tighter =

variable A B : Type
variable A B C : Type

def length (List A) : Nat
| [ ] => 0
Expand All @@ -19,3 +19,19 @@ def infixr ++ (xs ys : List A) : List A
def map (f : A -> B) (xs : List A) : List B elim xs
| [ ] => [ ]
| x :< xs' => f x :< map f xs'

def length-map (f : A -> B) (l : List A) : length (map f l) = length l elim l
| [ ] => refl
| x :< xs => pmap suc (length-map f xs)

def map-comp (g : B -> C) (f : A -> B) (l : List A) : map (\x => g (f x)) l = map g (map f l) elim l
| [ ] => refl
| x :< xs => pmap (g (f x) :<) (map-comp g f xs)

def map-id (l : List A) : map (\x => x) l = l
| [ ] => refl
| x :< xs => pmap (x :<) (map-id xs)

def head-def (x : A) (xs : List A) : A elim xs
| [ ] => x
| a :< _ => a
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import kala.collection.immutable.primitive.ImmutableIntSeq;
import kala.range.primitive.IntRange;
import kala.value.primitive.MutableIntValue;
import org.aya.generic.NameGenerator;
import org.aya.normalize.PatMatcher;
import org.aya.generic.State;
import org.aya.normalize.PatMatcher;
import org.aya.syntax.core.pat.Pat;
import org.aya.syntax.core.term.MetaPatTerm;
import org.aya.util.error.Panic;
Expand Down Expand Up @@ -230,8 +229,11 @@ private int bindAmount(@NotNull ImmutableSeq<Pat> pats) {

/// endregion Java Source Code Generate API

@Override
public PatternSerializer serialize(@NotNull ImmutableSeq<Matching> unit) {
@Override public PatternSerializer serialize(@NotNull ImmutableSeq<Matching> unit) {
if (unit.isEmpty()) {
onMismatch.accept(this);
return this;
}
var bindSize = unit.mapToInt(ImmutableIntSeq.factory(), x -> bindAmount(x.patterns));
int maxBindSize = bindSize.max();

Expand Down

0 comments on commit d6624a9

Please sign in to comment.