diff options
| author | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2025-12-14 13:05:04 +0100 |
|---|---|---|
| committer | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2025-12-14 16:46:04 +0100 |
| commit | 87e656c5cfebdbd2966494e8ef3f5504d328232a (patch) | |
| tree | 19f36a7346e24c8f97abe4f69a135a311d754341 /src | |
| parent | f2129e063bc5ee6241b2cf0891f8f39c8265ccb7 (diff) | |
Implement Tom's ixsFromIxS
that really helps in processing indexes using list functions
and getting back to the same type of index now that KnownNat
is removed from IxS and so the type information is harder to preserve.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Data/Array/Nested/Shaped/Shape.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs index 18bd2e9..6485c72 100644 --- a/src/Data/Array/Nested/Shaped/Shape.hs +++ b/src/Data/Array/Nested/Shaped/Shape.hs @@ -136,6 +136,17 @@ listsFromList topsh topl = go topsh topl ++ show (shsLength topsh) ++ ", list has length " ++ show (length topl) ++ ")" +{-# INLINEABLE listsFromListS #-} +listsFromListS :: ListS sh (Const i0) -> [i] -> ListS sh (Const i) +listsFromListS topl0 topl = go topl0 topl + where + go :: ListS sh (Const i0) -> [i] -> ListS sh (Const i) + go ZS [] = ZS + go (_ ::$ l0) (i : is) = Const i ::$ go l0 is + go _ _ = error $ "listsFromListS: Mismatched list length (the model says " + ++ show (listsLength topl0) ++ ", list has length " + ++ show (length topl) ++ ")" + {-# INLINEABLE listsToList #-} listsToList :: ListS sh (Const i) -> [i] listsToList list = build (\(cons :: i -> is -> is) (nil :: is) -> @@ -258,6 +269,10 @@ ixsRank (IxS l) = listsRank l ixsFromList :: forall sh i. ShS sh -> [i] -> IxS sh i ixsFromList = coerce (listsFromList @_ @i) +{-# INLINEABLE ixsFromIxS #-} +ixsFromIxS :: forall sh i0 i. IxS sh i0 -> [i] -> IxS sh i +ixsFromIxS = coerce (listsFromListS @_ @i0 @i) + {-# INLINEABLE ixsToList #-} ixsToList :: forall sh i. IxS sh i -> [i] ixsToList = coerce (listsToList @_ @i) |
