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

Safer backpermute #125

Open
mniip opened this issue Jul 8, 2024 · 0 comments
Open

Safer backpermute #125

mniip opened this issue Jul 8, 2024 · 0 comments

Comments

@mniip
Copy link

mniip commented Jul 8, 2024

Currently there are two versions of backpermute:

backpermute :: Vector m a -> Vector n Int -> Vector n a
unsafeBackpermute :: Vector m a -> Vector n Int -> Vector n a

The former does bounds checking to validate that the Int is a valid index for Vector m, the latter does not.

Seems like a missed opportunity to use a datatype that already did the bounds checking:

safeBackpermute :: Vector m a -> Vector n (Finite m) -> Vector n a

Possible implementation:

safeBackpermute xs is = Sized.unsafeBackpermute xs
  -- safe by construction of Finite m
  $ Sized.map (fromInteger . getFinite) is
  -- unsafeBackpermute already goes through Bundle, so this map should fuse
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

No branches or pull requests

1 participant