From fe25edfd8e633a834a23d272bae8ccf456b63c26 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 9 Apr 2026 00:59:15 +0200 Subject: Make equal-rank-coercibility part of the interface of ListX --- src/Data/Array/Nested/Convert.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/Data/Array/Nested/Convert.hs') diff --git a/src/Data/Array/Nested/Convert.hs b/src/Data/Array/Nested/Convert.hs index 671f40f..4ee2a71 100644 --- a/src/Data/Array/Nested/Convert.hs +++ b/src/Data/Array/Nested/Convert.hs @@ -46,6 +46,7 @@ import Unsafe.Coerce (unsafeCoerce) import Data.Array.Nested.Lemmas import Data.Array.Nested.Mixed +import Data.Array.Nested.Mixed.ListX import Data.Array.Nested.Mixed.Shape import Data.Array.Nested.Ranked.Base import Data.Array.Nested.Ranked.Shape @@ -58,9 +59,12 @@ import Data.Array.Nested.Types -- * To ranked ixrFromIxS :: forall sh i. IxS sh i -> IxR (Rank sh) i -ixrFromIxS = coerce - Prelude.. (unsafeCoerce :: IxX (MapJust sh) i -> IxX (Replicate (Rank sh) Nothing) i) - Prelude.. coerce +ixrFromIxS + | Refl <- lemRankReplicate (Proxy @(Rank sh)) + , Refl <- lemRankMapJust (Proxy @sh) + = coerce + Prelude.. (coerceEqualRankListX :: ListX (MapJust sh) i -> ListX (Replicate (Rank sh) Nothing) i) + Prelude.. coerce -- ixrFromIxX re-exported @@ -82,9 +86,12 @@ shrFromShX = coerce -- * To shaped ixsFromIxR :: forall sh i. IxR (Rank sh) i -> IxS sh i -ixsFromIxR = coerce - Prelude.. (unsafeCoerce :: IxX (Replicate (Rank sh) Nothing) i -> IxX (MapJust sh) i) - Prelude.. coerce +ixsFromIxR + | Refl <- lemRankReplicate (Proxy @(Rank sh)) + , Refl <- lemRankMapJust (Proxy @sh) + = coerce + Prelude.. (coerceEqualRankListX :: ListX (Replicate (Rank sh) Nothing) i -> ListX (MapJust sh) i) + Prelude.. coerce -- ixsFromIxX re-exported -- cgit v1.3