Skip to content

[ new ] Fin n as a refinement#2975

Open
gallais wants to merge 12 commits intoagda:masterfrom
gallais:nat-bounded
Open

[ new ] Fin n as a refinement#2975
gallais wants to merge 12 commits intoagda:masterfrom
gallais:nat-bounded

Conversation

@gallais
Copy link
Copy Markdown
Member

@gallais gallais commented Apr 8, 2026

This version has a better runtime representation
This version lets us have efficient implementations of things like splitAt and quotRem

I have been using this definition in my https://github.com/gallais/agda-tiling DSL and
it makes the library a lot faster.

I almost have feature parity with Data.Fin.Base (I have not implemented e.g. punchOut).

This version has a better runtime representation
This version lets us have efficient implementations of
things like splitAt and quotRem
@gallais gallais changed the title [ new ] Fin n as a refinement [ new ] Fin n as a refinement Apr 8, 2026
@jamesmckinna
Copy link
Copy Markdown
Collaborator

I think that this all looks great (but see also #2257 and #2292 which took a different angle of attack, focusing on modular arithmetic), but I'm a bit concerned about like-for-like emulation of the existing Data.Fin.Base API, when there are still many open issues drawing attention to... things which could be improved there. So I'm not sure I'd want to saddle us with the maintenance headache of fixing those issues on the new additions.

Also: where does this leave us wrt the 'propaganda' for DTFP with eg using Fin for type-safe/bounds-safe Data.Vec.Base.lookup?

gallais and others added 2 commits April 9, 2026 10:02
Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
gallais and others added 2 commits April 9, 2026 11:19
Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@jamesmckinna jamesmckinna left a comment

Choose a reason for hiding this comment

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

This all looks fine; lots of potential downstream uses/improvements, but worth landing this sooner rather than later.

@jamesmckinna
Copy link
Copy Markdown
Collaborator

@gallais do you want this badged for v2.4?

@gallais
Copy link
Copy Markdown
Member Author

gallais commented Apr 13, 2026

I am in no rush but also happy to see it included. I have a deadline today but should be able to have
a look (and merge your proposals; glad the sniping worked!) later this week.


¬T-≡ : ∀ {x} → (¬ T x) ⇔ x ≡ false
¬T-≡ {false} = mk⇔ (const refl) (const id)
¬T-≡ {true} = mk⇔ (contradiction _) (λ ())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lambda extends to rightmost scope so this can simplify to

Suggested change
¬T-≡ {true} = mk⇔ (contradiction _) (λ ())
¬T-≡ {true} = mk⇔ (contradiction _) λ()

where moreover I personally prefer λ() as a single unspaced lexeme (except it is in fact two!) for this distinguished use...

Copy link
Copy Markdown
Member Author

@gallais gallais Apr 14, 2026

Choose a reason for hiding this comment

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

Lambda extends to rightmost scope so this can simplify to

I hate this though.

Edit: more details; these two arguments play symmetric roles and I find it strange to break
the symmetry by using this quirk of the language (which I happen to hate).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The scoping, or the grouping? (That you hate)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The scoping!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was persuaded that rightmost made more sense back in the 1990s by Randy, but no longer quite sure how/why. True it's annoying forEquivalence etc, but that's an artefact of using a record constructor rather than a record binding?

@jamesmckinna
Copy link
Copy Markdown
Collaborator

Nice cleanup operation!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants