diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2026-04-09 00:59:15 +0200 |
|---|---|---|
| committer | Mikolaj Konarski <mikolaj.konarski@funktory.com> | 2026-04-09 18:39:54 +0200 |
| commit | 2e29470184d9b64b91d2709b7ac1f97f6c797886 (patch) | |
| tree | c8ea9b71575022cfc77569857aab7fb4306f20e6 /src/Data/Array/Nested/Mixed | |
| parent | 27f5fd474a85bd0c404215a1ce38ed378594e54b (diff) | |
Make equal-rank-coercibility part of the interface of ListX
Diffstat (limited to 'src/Data/Array/Nested/Mixed')
| -rw-r--r-- | src/Data/Array/Nested/Mixed/ListX.hs | 13 | ||||
| -rw-r--r-- | src/Data/Array/Nested/Mixed/Shape.hs | 12 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/Data/Array/Nested/Mixed/ListX.hs b/src/Data/Array/Nested/Mixed/ListX.hs index 51db341..e4e224b 100644 --- a/src/Data/Array/Nested/Mixed/ListX.hs +++ b/src/Data/Array/Nested/Mixed/ListX.hs @@ -23,7 +23,7 @@ {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} -module Data.Array.Nested.Mixed.ListX (ListX, pattern ZX, pattern (::%), listxShow, lazily, lazilyConcat, lazilyForce) where +module Data.Array.Nested.Mixed.ListX (ListX, pattern ZX, pattern (::%), listxShow, lazily, lazilyConcat, lazilyForce, Rank, coerceEqualRankListX) where import Control.DeepSeq (NFData(..)) import Data.Foldable qualified as Foldable @@ -38,6 +38,14 @@ import GHC.TypeLits.Orphans () import Data.Array.Nested.Types + +-- | The length of a type-level list. If the argument is a shape, then the +-- result is the rank of that shape. +type family Rank sh where + Rank '[] = 0 + Rank (_ : sh) = Rank sh + 1 + + -- * Mixed lists implementation -- | Data invariant: each element is in WHNF (the spine may be be not forced). @@ -132,3 +140,6 @@ instance IsList (ListX sh i) where fromList l = foldr seq () l `seq` ListX l {-# INLINE toList #-} toList = Foldable.toList + +coerceEqualRankListX :: Rank sh ~ Rank sh' => ListX sh i -> ListX sh' i +coerceEqualRankListX (ListX l) = ListX l diff --git a/src/Data/Array/Nested/Mixed/Shape.hs b/src/Data/Array/Nested/Mixed/Shape.hs index 671df2c..54e19e1 100644 --- a/src/Data/Array/Nested/Mixed/Shape.hs +++ b/src/Data/Array/Nested/Mixed/Shape.hs @@ -24,7 +24,10 @@ {-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.KnownNat.Solver #-} -module Data.Array.Nested.Mixed.Shape where +module Data.Array.Nested.Mixed.Shape ( + module Data.Array.Nested.Mixed.Shape, + Rank, +) where import Control.DeepSeq (NFData(..)) import Control.Exception (assert) @@ -47,13 +50,6 @@ import Data.Array.Nested.Mixed.ListX import Data.Array.Nested.Types --- | The length of a type-level list. If the argument is a shape, then the --- result is the rank of that shape. -type family Rank sh where - Rank '[] = 0 - Rank (_ : sh) = Rank sh + 1 - - -- * Mixed lists {-# INLINE listxFromList #-} |
