Skip to content

Commit 31cb16d

Browse files
committed
fixup: wait for overloading in nat solver goals
1 parent 8d102e5 commit 31cb16d

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed

src/Data/Nat/Solver.lagda.md

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ constructor handle addition and multiplication by $X_0$, it _also_
8282
handles weakening.
8383

8484
```agda
85-
_*X+_ : ∀ {n} (p : Poly A (suc n)) (q : Poly A n) → Poly A (suc n)
85+
_*X+_ : ∀ {n} (p : Poly A (suc n)) (q : Poly A n) → Poly A (suc n)
8686
```
8787

8888
<!--
@@ -578,21 +578,17 @@ expression of type `Nat`. This is _very_ useful when we are debugging.
578578

579579
```agda
580580
repr-macro : Nat → Term → TC ⊤
581-
repr-macro n hole =
582-
withNormalisation false $
583-
withReduceDefs (false , don't-reduce) $ do
581+
repr-macro n hole = withNormalisation false $
582+
withReduceDefs (false , don't-reduce) do
584583
tm ← quoteTC n
585584
e , vs ← build-expr empty-vars tm
586585
size , env ← environment vs
587586
repr ← normalise $ def (quote ↓_) (size h∷ e v∷ [])
588-
typeError $ strErr "The expression\n " ∷
589-
termErr tm ∷
590-
strErr "\nIs represented by the expression\n " ∷
591-
termErr e ∷
592-
strErr "\nAnd the polynomial\n " ∷
593-
termErr repr ∷
594-
strErr "\nThe environment is\n " ∷
595-
termErr env ∷ []
587+
typeError
588+
$ strErr "The expression\n " ∷ termErr tm
589+
∷ strErr "\nIs represented by the expression\n " ∷ termErr e
590+
∷ strErr "\nAnd the polynomial\n " ∷ termErr repr
591+
∷ strErr "\nThe environment is\n " ∷ termErr env ∷ []
596592
macro
597593
repr! : Nat → Term → TC ⊤
598594
repr! n = repr-macro n
@@ -605,9 +601,8 @@ which is bound to `C-c RET` by default.
605601

606602
```agda
607603
expand-macro : Nat → Term → TC ⊤
608-
expand-macro n hole =
609-
withNormalisation false $
610-
withReduceDefs (false , don't-reduce) $ do
604+
expand-macro n hole = withNormalisation false $
605+
withReduceDefs (false , don't-reduce) do
611606
tm ← quoteTC n
612607
e , vs ← build-expr empty-vars tm
613608
size , env ← environment vs
@@ -624,26 +619,25 @@ to automatically solve equations involving natural numbers.
624619

625620
```agda
626621
solve-macro : Term → TC ⊤
627-
solve-macro hole =
628-
withNormalisation false $
629-
withReduceDefs (false , don't-reduce) $ do
630-
goal ← infer-type hole >>= reduce
631-
632-
just (lhs , rhs) ← get-boundary goal
633-
where nothing → typeError $ strErr "Can't determine boundary: " ∷
634-
termErr goal ∷ []
622+
solve-macro hole = withNormalisation false $ withReduceDefs (false , don't-reduce) do
623+
goal ← infer-type hole >>= reduce >>= wait-for-type
624+
625+
just (lhs , rhs) ← get-boundary goal where
626+
nothing → typeError $ strErr "Can't determine boundary: " ∷ termErr goal ∷ []
627+
635628
elhs , vs ← build-expr empty-vars lhs
636629
erhs , vs ← build-expr vs rhs
637630
size , env ← environment vs
638631
(noConstraints $ unify hole (“solve” elhs erhs env)) <|> do
639632
nf-lhs ← normalise (“expand” elhs env)
640633
nf-rhs ← normalise (“expand” erhs env)
641-
typeError (strErr "Could not solve the following goal:\n " ∷
642-
termErr lhs ∷ strErr " ≡ " ∷ termErr rhs ∷
643-
strErr "\nComputed normal forms:\n LHS: " ∷
644-
termErr nf-lhs ∷
645-
strErr "\n RHS: " ∷
646-
termErr nf-rhs ∷ [])
634+
typeError
635+
$ strErr "Could not solve the following goal:\n "
636+
∷ termErr lhs ∷ strErr " ≡ " ∷ termErr rhs
637+
∷ strErr "\nComputed normal forms:\n LHS: "
638+
∷ termErr nf-lhs
639+
∷ strErr "\n RHS: " ∷ termErr nf-rhs
640+
∷ []
647641
648642
macro
649643
nat! : Term → TC ⊤
@@ -657,8 +651,8 @@ work for a moment.
657651

658652
```agda
659653
private
660-
wow-good-job : ∀ x y z
661-
→ (x + 5 + suc y) * z ≡ z * 5 + x * z + z + z * y
654+
wow-good-job
655+
: ∀ x y z → (x + 5 + suc y) * z ≡ z * 5 + x * z + z + z * y
662656
wow-good-job x y z = nat!
663657
```
664658

@@ -668,11 +662,9 @@ these proofs are already quite difficult to begin with. For the brave,
668662
here is what a sparse representation might look like.
669663

670664
```agda
671-
private
672-
data SparsePoly {a} (A : Type a) : Nat → Type a where
673-
const-sparse : ∀ {n} → A → SparsePoly A n
674-
shift : ∀ {n} → (j : Nat) → SparsePoly A n
675-
→ SparsePoly A (j + n)
676-
_*X^_+_ : ∀ {n} → SparsePoly A (suc n) → Nat → SparsePoly A n
677-
→ SparsePoly A (suc n)
665+
private data SparsePoly {a} (A : Type a) : Nat → Type a where
666+
const-sparse : ∀ {n} → A → SparsePoly A n
667+
shift : ∀ {n} → (j : Nat) → SparsePoly A n → SparsePoly A (j + n)
668+
_*X^_+_
669+
: ∀ {n} → SparsePoly A (suc n) → Nat → SparsePoly A n → SparsePoly A (suc n)
678670
```

0 commit comments

Comments
 (0)