diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2025-11-18 11:39:39 +0100 |
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2025-11-18 11:39:39 +0100 |
| commit | aeb62e1d59b4cdc426f6ca0ef8df6a0737bb0f86 (patch) | |
| tree | 3fb5c3255b19a4961d2adad8eb32b1a6ff66ebcd /src/Data/Array | |
| parent | 0ae9eeef25e72a0a69b6ed078d282f6892e1fc0b (diff) | |
Add shsEnum and shrEnum
Diffstat (limited to 'src/Data/Array')
| -rw-r--r-- | src/Data/Array/Nested/Ranked/Shape.hs | 7 | ||||
| -rw-r--r-- | src/Data/Array/Nested/Shaped/Shape.hs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Ranked/Shape.hs b/src/Data/Array/Nested/Ranked/Shape.hs index 488b4d8..a1fa247 100644 --- a/src/Data/Array/Nested/Ranked/Shape.hs +++ b/src/Data/Array/Nested/Ranked/Shape.hs @@ -330,6 +330,13 @@ shrZipWith f (ShR l1) (ShR l2) = ShR $ listrZipWith f l1 l2 shrPermutePrefix :: forall n i. [Int] -> ShR n i -> ShR n i shrPermutePrefix = coerce (listrPermutePrefix @i) +shrEnum :: IShR sh -> [IIxR sh] +shrEnum = \sh -> go sh id [] + where + go :: IShR sh -> (IIxR sh -> a) -> [a] -> [a] + go ZSR f = (f ZIR :) + go (n :$: sh) f = foldr (.) id [go sh (f . (i :.:)) | i <- [0 .. n - 1]] + -- | Untyped: length is checked at runtime. instance KnownNat n => IsList (ListR n i) where diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs index 10e1a9d..6eaec10 100644 --- a/src/Data/Array/Nested/Shaped/Shape.hs +++ b/src/Data/Array/Nested/Shaped/Shape.hs @@ -389,6 +389,13 @@ shsFromListS (_ ::$ l) = SNat :$$ shsFromListS l shsFromIxS :: IxS sh i -> ShS sh shsFromIxS (IxS l) = shsFromListS l +shsEnum :: ShS sh -> [IIxS sh] +shsEnum = \sh -> go sh id [] + where + go :: ShS sh -> (IIxS sh -> a) -> [a] -> [a] + go ZSS f = (f ZIS :) + go (n :$$ sh) f = foldr (.) id [go sh (f . (i :.$)) | i <- [0 .. fromSNat' n - 1]] + -- | Untyped: length is checked at runtime. instance KnownShS sh => IsList (ListS sh (Const i)) where |
