aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikolaj Konarski <mikolaj.konarski@funktory.com>2025-12-01 17:15:05 +0100
committerMikolaj Konarski <mikolaj.konarski@funktory.com>2025-12-01 17:15:05 +0100
commit0028b655341069e83db6e0bfde01dea1c696f5aa (patch)
treed43e18d574654043b81ccfaaa3c9ae9e7784dc91
parent9560d0f26420409afd2230fb7e5e111eafcced06 (diff)
Unify toList functions for shapes
-rw-r--r--src/Data/Array/Nested/Mixed/Shape.hs5
-rw-r--r--src/Data/Array/Nested/Ranked/Shape.hs3
-rw-r--r--src/Data/Array/Nested/Shaped/Shape.hs5
3 files changed, 13 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Mixed/Shape.hs b/src/Data/Array/Nested/Mixed/Shape.hs
index a9ed2d0..4626481 100644
--- a/src/Data/Array/Nested/Mixed/Shape.hs
+++ b/src/Data/Array/Nested/Mixed/Shape.hs
@@ -140,6 +140,7 @@ listxFromList topssh topl = go topssh topl
++ show (ssxLength topssh) ++ ", list has length "
++ show (length topl) ++ ")"
+{-# INLINEABLE listxToList #-}
listxToList :: ListX sh' (Const i) -> [i]
listxToList ZX = []
listxToList (Const i ::% is) = i : listxToList is
@@ -219,6 +220,9 @@ instance Foldable (IxX sh) where
{-# INLINE foldr #-}
foldr _ z ZIX = z
foldr f z (x :.% xs) = f x (foldr f z xs)
+ {-# INLINEABLE toList #-}
+ toList ZIX = []
+ toList (i :.% is) = i : Foldable.toList is
null ZIX = False
null _ = True
@@ -441,6 +445,7 @@ shxFromList topssh topl = go topssh topl
++ show (ssxLength topssh) ++ ", list has length "
++ show (length topl) ++ ")"
+{-# INLINEABLE shxToList #-}
shxToList :: IShX sh -> [Int]
shxToList ZSX = []
shxToList (smn :$% sh) = fromSMayNat' smn : shxToList sh
diff --git a/src/Data/Array/Nested/Ranked/Shape.hs b/src/Data/Array/Nested/Ranked/Shape.hs
index 989d7d1..739f0de 100644
--- a/src/Data/Array/Nested/Ranked/Shape.hs
+++ b/src/Data/Array/Nested/Ranked/Shape.hs
@@ -79,6 +79,9 @@ instance Foldable (ListR n) where
{-# INLINE foldr #-}
foldr _ z ZR = z
foldr f z (x ::: xs) = f x (foldr f z xs)
+ {-# INLINEABLE toList #-}
+ toList ZR = []
+ toList (i ::: is) = i : Foldable.toList is
null ZR = False
null _ = True
diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs
index c1e687a..bbcdbf9 100644
--- a/src/Data/Array/Nested/Shaped/Shape.hs
+++ b/src/Data/Array/Nested/Shaped/Shape.hs
@@ -126,6 +126,7 @@ listsRank :: ListS sh f -> SNat (Rank sh)
listsRank ZS = SNat
listsRank (_ ::$ sh) = snatSucc (listsRank sh)
+{-# INLINEABLE listsToList #-}
listsToList :: ListS sh (Const i) -> [i]
listsToList ZS = []
listsToList (Const i ::$ is) = i : listsToList is
@@ -229,6 +230,9 @@ instance Foldable (IxS sh) where
{-# INLINE foldr #-}
foldr _ z ZIS = z
foldr f z (x :.$ xs) = f x (foldr f z xs)
+ {-# INLINEABLE toList #-}
+ toList ZIS = []
+ toList (i :.$ is) = i : Foldable.toList is
null ZIS = False
null _ = True
@@ -335,6 +339,7 @@ shsSize :: ShS sh -> Int
shsSize ZSS = 1
shsSize (n :$$ sh) = fromSNat' n * shsSize sh
+{-# INLINEABLE shsToList #-}
shsToList :: ShS sh -> [Int]
shsToList ZSS = []
shsToList (sn :$$ sh) = fromSNat' sn : shsToList sh