aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Permutation.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Array/Nested/Permutation.hs')
-rw-r--r--src/Data/Array/Nested/Permutation.hs39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/Data/Array/Nested/Permutation.hs b/src/Data/Array/Nested/Permutation.hs
index ee79ecf..19d81f0 100644
--- a/src/Data/Array/Nested/Permutation.hs
+++ b/src/Data/Array/Nested/Permutation.hs
@@ -31,7 +31,6 @@ import GHC.TypeNats qualified as TN
import Data.Array.Nested.Mixed.Shape
import Data.Array.Nested.Types
-import Data.Array.Nested.Mixed.ListX
-- * Permutations
@@ -222,31 +221,29 @@ ssxPermutePrefix :: Perm is -> StaticShX sh -> StaticShX (PermutePrefix is sh)
ssxPermutePrefix = coerce (shxPermutePrefix @())
-listxTakeLenPerm :: forall i is sh. Perm is -> ListX sh i -> ListX (TakeLen is sh) i
-listxTakeLenPerm PNil _ = ZX
-listxTakeLenPerm (_ `PCons` is) (n ::% sh) = n ::% listxTakeLenPerm is sh
-listxTakeLenPerm (_ `PCons` _) ZX = error "Permutation longer than shape"
+ixxTakeLenPerm :: forall i is sh. Perm is -> IxX sh i -> IxX (TakeLen is sh) i
+ixxTakeLenPerm PNil _ = ZIX
+ixxTakeLenPerm (_ `PCons` is) (n :.% sh) = n :.% ixxTakeLenPerm is sh
+ixxTakeLenPerm (_ `PCons` _) ZIX = error "Permutation longer than shape"
-listxDropLenPerm :: forall i is sh. Perm is -> ListX sh i -> ListX (DropLen is sh) i
-listxDropLenPerm PNil sh = sh
-listxDropLenPerm (_ `PCons` is) (_ ::% sh) = listxDropLenPerm is sh
-listxDropLenPerm (_ `PCons` _) ZX = error "Permutation longer than shape"
+ixxDropLenPerm :: forall i is sh. Perm is -> IxX sh i -> IxX (DropLen is sh) i
+ixxDropLenPerm PNil sh = sh
+ixxDropLenPerm (_ `PCons` is) (_ :.% sh) = ixxDropLenPerm is sh
+ixxDropLenPerm (_ `PCons` _) ZIX = error "Permutation longer than shape"
-listxPermute :: forall i is sh. Perm is -> ListX sh i -> ListX (Permute is sh) i
-listxPermute PNil _ = ZX
-listxPermute (i `PCons` (is :: Perm is')) (sh :: ListX sh f) =
- listxIndex i sh ::% listxPermute is sh
+ixxPermute :: forall i is sh. Perm is -> IxX sh i -> IxX (Permute is sh) i
+ixxPermute PNil _ = ZIX
+ixxPermute (i `PCons` (is :: Perm is')) (sh :: IxX sh f) =
+ ixxIndex i sh :.% ixxPermute is sh
-listxIndex :: forall j i sh. SNat i -> ListX sh j -> j
-listxIndex SZ (n ::% _) = n
-listxIndex (SS i) (_ ::% sh) = listxIndex i sh
-listxIndex _ ZX = error "Index into empty shape"
-
-listxPermutePrefix :: forall i is sh. Perm is -> ListX sh i -> ListX (PermutePrefix is sh) i
-listxPermutePrefix perm sh = listxAppend (listxPermute perm (listxTakeLenPerm perm sh)) (listxDropLenPerm perm sh)
+ixxIndex :: forall j i sh. SNat i -> IxX sh j -> j
+ixxIndex SZ (n :.% _) = n
+ixxIndex (SS i) (_ :.% sh) = ixxIndex i sh
+ixxIndex _ ZIX = error "Index into empty shape"
ixxPermutePrefix :: forall i is sh. Perm is -> IxX sh i -> IxX (PermutePrefix is sh) i
-ixxPermutePrefix = coerce (listxPermutePrefix @i)
+ixxPermutePrefix perm sh = ixxAppend (ixxPermute perm (ixxTakeLenPerm perm sh)) (ixxDropLenPerm perm sh)
+
-- * Operations on permutations