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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant