aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Convert.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Array/Nested/Convert.hs')
-rw-r--r--src/Data/Array/Nested/Convert.hs23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/Data/Array/Nested/Convert.hs b/src/Data/Array/Nested/Convert.hs
index 86534f1..408bf8a 100644
--- a/src/Data/Array/Nested/Convert.hs
+++ b/src/Data/Array/Nested/Convert.hs
@@ -18,7 +18,7 @@ module Data.Array.Nested.Convert (
ixrFromIxS, ixrFromIxX, shrFromShS, shrFromShXAnyShape, shrFromShX,
listrCast, ixrCast, shrCast,
-- ** To shaped
- ixsFromIxR, ixsFromIxR', ixsFromIxX, ixsFromIxX', withShsFromShR, shsFromShX, withShsFromShX, shsFromSSX,
+ ixsFromIxR, ixsFromIxX, ixsFromIxX', withShsFromShR, shsFromShX, withShsFromShX, shsFromSSX,
ixsCast,
-- ** To mixed
ixxFromIxR, ixxFromIxS, shxFromShR, shxFromShS,
@@ -59,7 +59,8 @@ import Data.Array.Nested.Types
-- TODO: change all those unsafeCoerces into coerces by defining shaped
-- and ranekd index types as newtypes of the mixed index type
--- and similarly for the sized lists
+-- and similarly for the sized lists or, preferably, by defining
+-- all as newtypes over [], exploiting fusion and getting free toList.
ixrFromIxS :: IxS sh i -> IxR (Rank sh) i
ixrFromIxS = unsafeCoerce
@@ -82,25 +83,13 @@ shrFromShX = coerce
-- * To shaped
--- TODO: remove the ShS now that no KnownNats is inside IxS.
-ixsFromIxR :: ShS sh -> IxR (Rank sh) i -> IxS sh i
-ixsFromIxR _ = unsafeCoerce
-
--- TODO: if possible, remove the ShS now that no KnownNats is inside IxS.
--- | Performs a runtime check that @n@ matches @Rank sh@. Equivalent to the
--- following, but more efficient:
---
--- > ixsFromIxR' sh idx = ixsFromIxR sh (ixrCast (shsRank sh) idx)
-ixsFromIxR' :: ShS sh -> IxR n i -> IxS sh i
-ixsFromIxR' ZSS ZIR = ZIS
-ixsFromIxR' (_ :$$ sh) (n :.: idx) = n :.$ ixsFromIxR' sh idx
-ixsFromIxR' _ _ = error "ixsFromIxR': index rank does not match shape rank"
+ixsFromIxR :: IxR (Rank sh) i -> IxS sh i
+ixsFromIxR = unsafeCoerce -- TODO: switch to coerce once newtypes overhauled
-- ixsFromIxX re-exported
--- TODO: if possible, remove the ShS now that no KnownNats is inside IxS.
-- | Performs a runtime check that @Rank sh'@ match @Rank sh@. Equivalent to
--- the following, but more efficient:
+-- the following, but less verbose:
--
-- > ixsFromIxX' sh idx = ixsFromIxX sh (ixxCast (shxFromShS sh) idx)
ixsFromIxX' :: ShS sh -> IxX sh' i -> IxS sh i