Skip to content

Safer backpermute #125

@mniip

Description

@mniip

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions