aboutsummaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-10-09 09:25:07 +0200
committerTom Smeding <tom@tomsmeding.com>2024-10-09 09:25:07 +0200
commit62c4d56bfb75e933b5307930859f6c9366217ab1 (patch)
tree60579d096304037c6990b424d618f077a2aeccc3 /src/Data
parent48bb58de893bdd28a8bae534bf618fb5790833ca (diff)
Add rToMixed and stoMixed
These are somewhat redundant because one can just open up the Ranked and Shaped newtype constructors, but let's complete the triangle of conversion functions.
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Array/Nested.hs6
-rw-r--r--src/Data/Array/Nested/Internal/Ranked.hs3
-rw-r--r--src/Data/Array/Nested/Internal/Shaped.hs3
3 files changed, 10 insertions, 2 deletions
diff --git a/src/Data/Array/Nested.hs b/src/Data/Array/Nested.hs
index 7eb7b18..e4bd517 100644
--- a/src/Data/Array/Nested.hs
+++ b/src/Data/Array/Nested.hs
@@ -18,7 +18,7 @@ module Data.Array.Nested (
rlift, rlift2,
-- ** Conversions
rtoXArrayPrim, rfromXArrayPrim,
- rcastToShaped,
+ rcastToShaped, rtoMixed,
rfromOrthotope, rtoOrthotope,
-- * Shaped arrays
@@ -39,7 +39,7 @@ module Data.Array.Nested (
slift, slift2,
-- ** Conversions
stoXArrayPrim, sfromXArrayPrim,
- stoRanked,
+ stoRanked, stoMixed,
sfromOrthotope, stoOrthotope,
-- * Mixed arrays
@@ -78,6 +78,8 @@ module Data.Array.Nested (
KnownPerm(..),
NumElt, FloatElt,
Rank,
+ Replicate,
+ MapJust,
) where
import Prelude hiding (mappend, mconcat)
diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs
index 735d1a3..ffa1cea 100644
--- a/src/Data/Array/Nested/Internal/Ranked.hs
+++ b/src/Data/Array/Nested/Internal/Ranked.hs
@@ -524,3 +524,6 @@ mtoRanked arr
convSh (smn :$% (sh :: IShX sh'T))
| Refl <- lemReplicateSucc @(Nothing @Nat) @(Rank sh'T)
= SUnknown (fromSMayNat' smn) :$% convSh sh
+
+rtoMixed :: forall n a. Elt a => Ranked n a -> Mixed (Replicate n Nothing) a
+rtoMixed (Ranked arr) = arr
diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs
index 995507f..023f96c 100644
--- a/src/Data/Array/Nested/Internal/Shaped.hs
+++ b/src/Data/Array/Nested/Internal/Shaped.hs
@@ -459,3 +459,6 @@ mcastToShaped arr targetsh
, Refl <- lemAppNil @(MapJust sh')
, Refl <- lemRankMapJust targetsh
= Shaped (mcast (ssxFromShape (mshape arr)) (shCvtSX targetsh) (Proxy @'[]) arr)
+
+stoMixed :: forall sh a. Shaped sh a -> Mixed (MapJust sh) a
+stoMixed (Shaped arr) = arr