From 53bc096c807fc63cfe5f1102131b475deb5e21ca Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 4 Apr 2026 12:09:08 +0200 Subject: Remove almost all unsafeCoerce --- src/Data/Array/Nested/Shaped/Shape.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/Data/Array/Nested/Shaped/Shape.hs') diff --git a/src/Data/Array/Nested/Shaped/Shape.hs b/src/Data/Array/Nested/Shaped/Shape.hs index 97d1559..c39d482 100644 --- a/src/Data/Array/Nested/Shaped/Shape.hs +++ b/src/Data/Array/Nested/Shaped/Shape.hs @@ -36,7 +36,6 @@ import GHC.Exts (build, withDict) import GHC.IsList (IsList) import GHC.IsList qualified as IsList import GHC.TypeLits -import Unsafe.Coerce (unsafeCoerce) import Data.Array.Nested.Mixed.Shape import Data.Array.Nested.Permutation @@ -267,22 +266,21 @@ 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 -- TODO: switch to coerce once newtypes overhauled +ixxFromIxS = coerce {-# 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 -- TODO: switch to coerce once newtypes overhauled +ixsFromIxX = coerce shsEnum :: ShS sh -> [IIxS sh] 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 +shsEnum' (ShS sh) = (coerce :: [IxX (MapJust sh) i] -> [IxS sh i]) $ shxEnum' sh -- * Shaped shapes @@ -346,8 +344,7 @@ shsLength (ShS shx) = shxLength shx shsRank :: forall sh. ShS sh -> SNat (Rank sh) shsRank (ShS shx) = - gcastWith (unsafeCoerceRefl - :: Rank (MapJust sh) :~: Rank sh) $ + gcastWith (unsafeCoerceRefl :: Rank (MapJust sh) :~: Rank sh) $ shxRank shx shsSize :: ShS sh -> Int -- cgit v1.3