Skip to content

refactor: use a refinement type for Data.Vec#586

Open
4e554c4c wants to merge 28 commits intothe1lab:mainfrom
4e554c4c:refinement
Open

refactor: use a refinement type for Data.Vec#586
4e554c4c wants to merge 28 commits intothe1lab:mainfrom
4e554c4c:refinement

Conversation

@4e554c4c
Copy link
Contributor

resolves: #567

Description

As per a suggestion by @TOTBWF, this changes Data.Vec to use a refinement type which codes length xs = n.

Unfortunately this means that induction on vecs now needs vec-view, which makes some things messier. Worse still, I can't seem to use [] as a pattern for the empty vec since it conflicts with list, and use at all since it can't be a pattern.

The order of instances is also changed a little bit, which means [ p ] fails to realize as a list in 1Lab.Reflection.List.

I'd love some tips on how to make this a little bit cleaner :)

Checklist

Before submitting a merge request, please check the items below:

  • I've read the contributing guidelines.
  • The imports of new modules have been sorted with support/sort-imports.hs (or nix run --experimental-features nix-command -f . sort-imports).
  • All new code blocks have "agda" as their language.

@Lavenza
Copy link
Member

Lavenza commented Jan 21, 2026

Pull request preview

Changed pages

Comment on lines +48 to +58
instance
Length-zero : Length {A = A} [] zero
Length-zero = zero

Length-suc : ∀ {x n} {xs : List A} → ⦃ _ : Length xs n ⦄
→ Length (x ∷ xs) (suc n)
Length-suc ⦃ l ⦄ = suc l

Length-length : ∀ {xs : List A} → Length xs (length xs)
Length-length {xs = []} = zero
Length-length {xs = x ∷ xs} = suc Length-length
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a point to having these as instances? Also, I think Length-length would have to be marked INCOHERENT...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i ran into this at some point yeahg

TOTBWF added 21 commits March 2, 2026 09:28
This makes a lot of inductive arguments easier
Now that lower < n is a definitional proposition,
we don't need to worry about irrelevance here
This file typechecks, but I suspect that there is an Agda bug lurking
in the shaddows. If you try to typecheck Homotopy.Truncation, a call
to elim! throws the following error:

> Projection  _≤_.is-leq  is irrelevant.
> Turn on option --irrelevant-projections to use it (unsafe)
> when checking that the expression ._≤_.is-leq (Leq-refl {n}) has
> type Data.Bool.Base.is-true (suc (suc n) ≤? suc (suc n))

This seems to trigger when resolving the 'Inductive' instance using
Inductive-n-Tr, which has the type

> Inductive-n-Tr
>   : ∀ {ℓ ℓ' ℓm} {A : Type ℓ} {n} {P : n-Tr A (suc n) → Type ℓ'} ⦃ i : Inductive (∀ x → P (inc x)) ℓm ⦄
>   → ⦃ _ : ∀ {x} → H-Level (P x) (suc n) ⦄
>   → Inductive (∀ x → P x) ℓm

Moreover, the problematic elim! is eliminating into the universe of
n-Types, which require us to use a hlevel-projection, so I think that
some sequence of events is causing the proof Leq-refl {n} to get
η-expanded to a (bogus) irrelevant projection, which then gets
re-checked by reflection, which then (rightfully) complains.
This seems to solve the issues with Homotopy.Truncation
resolves: the1lab#567

Co-authored-by: Reed Mullanix <reedmullanix@gmail.com>
@4e554c4c
Copy link
Contributor Author

4e554c4c commented Mar 2, 2026

this is now rebased on #597 and doesn't chmod borceaux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Data.Vec to use a refinement type ala Fin

4 participants