From 4a4e0f7f9f1131477d26aa24f4eab1741d209260 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sun, 11 May 2025 12:37:28 +0200 Subject: Define fooLength and/or fooRank whenever not yet defined --- src/Data/Array/Mixed/Shape.hs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Data/Array/Mixed') diff --git a/src/Data/Array/Mixed/Shape.hs b/src/Data/Array/Mixed/Shape.hs index 16f62fe..80bd55e 100644 --- a/src/Data/Array/Mixed/Shape.hs +++ b/src/Data/Array/Mixed/Shape.hs @@ -184,6 +184,12 @@ instance Foldable (IxX sh) where instance NFData i => NFData (IxX sh i) +ixxLength :: IxX sh i -> Int +ixxLength (IxX l) = listxLength l + +ixxRank :: IxX sh i -> SNat (Rank sh) +ixxRank (IxX l) = listxRank l + ixxZero :: StaticShX sh -> IIxX sh ixxZero ZKX = ZIX ixxZero (_ :!% ssh) = 0 :.% ixxZero ssh @@ -305,12 +311,6 @@ instance NFData i => NFData (ShX sh i) where rnf (ShX (SUnknown i ::% l)) = rnf i `seq` rnf (ShX l) rnf (ShX (SKnown SNat ::% l)) = rnf (ShX l) -shxLength :: ShX sh i -> Int -shxLength (ShX l) = listxLength l - -shxRank :: ShX sh i -> SNat (Rank sh) -shxRank (ShX list) = listxRank list - -- | This checks only whether the types are equal; unknown dimensions might -- still differ. This corresponds to 'testEquality', except on the penultimate -- type parameter. @@ -340,6 +340,12 @@ shxEqual (SUnknown i :$% sh) (SUnknown j :$% sh') = Just Refl shxEqual _ _ = Nothing +shxLength :: ShX sh i -> Int +shxLength (ShX l) = listxLength l + +shxRank :: ShX sh i -> SNat (Rank sh) +shxRank (ShX l) = listxRank l + -- | The number of elements in an array described by this shape. shxSize :: IShX sh -> Int shxSize ZSX = 1 @@ -452,6 +458,9 @@ instance TestEquality StaticShX where ssxLength :: StaticShX sh -> Int ssxLength (StaticShX l) = listxLength l +ssxRank :: StaticShX sh -> SNat (Rank sh) +ssxRank (StaticShX l) = listxRank l + -- | @ssxEqType = 'testEquality'@. Provided for consistency. ssxEqType :: StaticShX sh -> StaticShX sh' -> Maybe (sh :~: sh') ssxEqType = testEquality -- cgit v1.2.3-70-g09d2