diff options
| author | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2026-04-04 16:26:06 +0200 |
|---|---|---|
| committer | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2026-04-04 20:52:32 +0200 |
| commit | ee319119b1f24db2b2e981e303db9935a1dca425 (patch) | |
| tree | 818218affd29d640b7842c8ef668964f556a30c7 /src/Data/Array/Nested/Shaped/Shape.hs | |
| parent | 53bc096c807fc63cfe5f1102131b475deb5e21ca (diff) | |
Remove copies of length and toList operations that Foldable already provides
in preparation for deriving Foldable for []
Diffstat (limited to 'src/Data/Array/Nested/Shaped/Shape.hs')
| -rw-r--r-- | src/Data/Array/Nested/Shaped/Shape.hs | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs index c39d482..274f954 100644 --- a/src/Data/Array/Nested/Shaped/Shape.hs +++ b/src/Data/Array/Nested/Shaped/Shape.hs @@ -89,9 +89,6 @@ listsShow f l = showString "[" . go "" l . showString "]" go _ ZS = id go prefix (x ::$ xs) = showString prefix . f x . go "," xs -listsLength :: ListS sh i -> Int -listsLength = length - listsRank :: ListS sh i -> SNat (Rank sh) listsRank ZS = SNat listsRank (_ ::$ sh) = snatSucc (listsRank sh) @@ -114,17 +111,9 @@ listsFromListS topl0 topl = go topl0 topl go ZS [] = ZS go (_ ::$ l0) (i : is) = i ::$ go l0 is go _ _ = error $ "listsFromListS: Mismatched list length (the model says " - ++ show (listsLength topl0) ++ ", list has length " + ++ show (length topl0) ++ ", list has length " ++ show (length topl) ++ ")" -{-# INLINEABLE listsToList #-} -listsToList :: ListS sh i -> [i] -listsToList list = build (\(cons :: i -> is -> is) (nil :: is) -> - let go :: ListS sh i -> is - go ZS = nil - go (i ::$ is) = i `cons` go is - in go list) - listsHead :: ListS (n : sh) i -> i listsHead (i ::$ _) = i @@ -208,9 +197,6 @@ instance Show i => Show (IxS sh i) where showsPrec _ (IxS l) = listsShow (\i -> shows i) l #endif -ixsLength :: IxS sh i -> Int -ixsLength (IxS l) = listsLength l - ixsRank :: IxS sh i -> SNat (Rank sh) ixsRank (IxS l) = listsRank l @@ -221,9 +207,6 @@ ixsFromList = coerce (listsFromList @_ @i) ixsFromIxS :: forall sh i0 i. IxS sh i0 -> [i] -> IxS sh i ixsFromIxS = coerce (listsFromListS @_ @i0 @i) -ixsToList :: IxS sh i -> [i] -ixsToList = Foldable.toList - ixsZero :: ShS sh -> IIxS sh ixsZero ZSS = ZIS ixsZero (_ :$$ sh) = 0 :.$ ixsZero sh @@ -481,7 +464,7 @@ shsOrthotopeShape (SNat :$$ sh) | Dict <- shsOrthotopeShape sh = Dict instance KnownShS sh => IsList (ListS sh i) where type Item (ListS sh i) = i fromList = listsFromList (knownShS @sh) - toList = listsToList + toList = Foldable.toList -- | Very untyped: only length is checked (at runtime), index bounds are __not checked__. instance KnownShS sh => IsList (IxS sh i) where |
