Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: monadic defs for statically sized vectors #925

Closed

Conversation

Shreyas4991
Copy link
Contributor

This PR is the first follow up to #793. It adds all the monadic definitions for Vectors that correspond to similar definitions for Arrays in core and Batteries as well as defs which are immediately downstream of them. There are no plans to add theorems in this PR.

-[] Add all monadic definitions from Init.Data.Array.Basic and their downstream definitions for Vectors.
-[] Add all monadic definitions from Batteries.Data.Array.Basic and their downstream definitions for Vectors.

@Shreyas4991
Copy link
Contributor Author

WIP

@github-actions github-actions bot added the WIP work in progress label Aug 17, 2024
def modifyM [Monad m] (v : Vector α n) (i : Nat)
(f : α → m α) : m (Vector α n) := do
return ⟨←Array.modifyM v.toArray i f,
by rw[←v.size_eq]; sorry⟩
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any help in fixing this sorry is welcome. I found a lemma by the name Array.size_modifyM which however is not a straightforward equality.

-/
def mapM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m]
(f : α → m β) (v : Vector α n) : m (Vector β n) := do
return ⟨←Array.mapM f v.toArray, by rw[←v.size_eq]; sorry⟩
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sorry is also stuck for the same reason as the above comment because the corresponding Array API uses Satisfies. I am grateful for any help with these situations

def mapIdxM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m]
(v : Vector α n) (f : Fin n → α → m β) : m (Vector β n) := do
return ⟨←Array.mapIdxM v.toArray (v.size_eq.symm ▸ f),
by rw[←v.size_eq]; sorry⟩
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another sorry that I am stuck at because the relevant API lemma uses the Satisfies predicate.

@kim-em kim-em added the awaiting-author Waiting for PR author to address issues label Jan 30, 2025
@kim-em
Copy link
Collaborator

kim-em commented Jan 30, 2025

Most of these have since been implemented upstream. I'm going to close now, but if you'd like to open a PR filling any remaining gaps, that would be great.

See https://github.com/leanprover/lean4/blob/master/tests/lean/run/list_monadic_functions.lean for a map of the current implementation status.

@kim-em kim-em closed this Jan 30, 2025
@Shreyas4991
Copy link
Contributor Author

Shreyas4991 commented Jan 30, 2025

@kim-em : the defs modifyM, forRevM, findRevM, findSomeRevM, and findIdxM are already in this PR and not yet in core according to the list.

@kim-em
Copy link
Collaborator

kim-em commented Jan 30, 2025

Ok, if those are ready could you open a new PR containing just those?

@Shreyas4991
Copy link
Contributor Author

Ok, if those are ready could you open a new PR containing just those?

#1107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author Waiting for PR author to address issues WIP work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants