diff options
Diffstat (limited to 'src/Data/Array')
| -rw-r--r-- | src/Data/Array/Nested/Convert.hs | 23 | ||||
| -rw-r--r-- | src/Data/Array/Nested/Ranked/Shape.hs | 6 | ||||
| -rw-r--r-- | src/Data/Array/Nested/Shaped/Shape.hs | 6 |
3 files changed, 12 insertions, 23 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 diff --git a/src/Data/Array/Nested/Ranked/Shape.hs b/src/Data/Array/Nested/Ranked/Shape.hs index 2415e26..6d47ade 100644 --- a/src/Data/Array/Nested/Ranked/Shape.hs +++ b/src/Data/Array/Nested/Ranked/Shape.hs @@ -293,7 +293,7 @@ ixrToLinear :: Num i => IShR m -> IxR m i -> i ixrToLinear (ShR sh) ix = ixxToLinear sh (ixxFromIxR ix) ixxFromIxR :: IxR n i -> IxX (Replicate n Nothing) i -ixxFromIxR = unsafeCoerce +ixxFromIxR = unsafeCoerce -- TODO: switch to coerce once newtypes overhauled {-# INLINEABLE ixrFromLinear #-} ixrFromLinear :: forall i m. Num i => IShR m -> Int -> IxR m i @@ -302,7 +302,7 @@ ixrFromLinear (ShR sh) i = ixrFromIxX $ ixxFromLinear sh i ixrFromIxX :: IxX sh i -> IxR (Rank sh) i -ixrFromIxX = unsafeCoerce +ixrFromIxX = unsafeCoerce -- TODO: switch to coerce once newtypes overhauled shrEnum :: IShR n -> [IIxR n] shrEnum = shrEnum' @@ -312,7 +312,7 @@ shrEnum' :: forall i n. Num i => IShR n -> [IxR n i] shrEnum' (ShR sh) | Refl <- lemRankReplicate (Proxy @n) = (unsafeCoerce :: [IxX (Replicate n Nothing) i] -> [IxR n i]) $ shxEnum' sh - + -- TODO: switch to coerce once newtypes overhauled -- * Ranked shapes diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs index 8cd937c..c5e3202 100644 --- a/src/Data/Array/Nested/Shaped/Shape.hs +++ b/src/Data/Array/Nested/Shaped/Shape.hs @@ -275,14 +275,14 @@ ixsToLinear :: Num i => ShS sh -> IxS sh i -> i ixsToLinear (ShS sh) ix = ixxToLinear sh (ixxFromIxS ix) ixxFromIxS :: IxS sh i -> IxX (MapJust sh) i -ixxFromIxS = unsafeCoerce +ixxFromIxS = unsafeCoerce -- TODO: switch to coerce once newtypes overhauled {-# INLINEABLE ixsFromLinear #-} ixsFromLinear :: Num i => ShS sh -> Int -> IxS sh i ixsFromLinear (ShS sh) i = ixsFromIxX $ ixxFromLinear sh i ixsFromIxX :: IxX (MapJust sh) i -> IxS sh i -ixsFromIxX = unsafeCoerce +ixsFromIxX = unsafeCoerce -- TODO: switch to coerce once newtypes overhauled shsEnum :: ShS sh -> [IIxS sh] shsEnum = shsEnum' @@ -290,7 +290,7 @@ shsEnum = shsEnum' {-# INLINABLE shsEnum' #-} -- ensure this can be specialised at use site shsEnum' :: Num i => ShS sh -> [IxS sh i] shsEnum' (ShS sh) = (unsafeCoerce :: [IxX (MapJust sh) i] -> [IxS sh i]) $ shxEnum' sh - + -- TODO: switch to coerce once newtypes overhauled -- * Shaped shapes |
