From bf4a469f369f1b8c6b1c2d7cc6907177405603f4 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 13 Nov 2024 20:20:30 +0100 Subject: Add withKnownSh{S,X} --- src/Data/Array/Nested/Internal/Shape.hs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Data/Array/Nested') diff --git a/src/Data/Array/Nested/Internal/Shape.hs b/src/Data/Array/Nested/Internal/Shape.hs index b7bbf4c..59f2c9a 100644 --- a/src/Data/Array/Nested/Internal/Shape.hs +++ b/src/Data/Array/Nested/Internal/Shape.hs @@ -34,6 +34,7 @@ import Data.Kind (Type, Constraint) import Data.Monoid (Sum(..)) import Data.Proxy import Data.Type.Equality +import GHC.Exts (withDict) import GHC.IsList (IsList) import GHC.IsList qualified as IsList import GHC.TypeLits @@ -558,6 +559,9 @@ class KnownShS sh where knownShS :: ShS sh instance KnownShS '[] where knownShS = ZSS instance (KnownNat n, KnownShS sh) => KnownShS (n : sh) where knownShS = natSing :$$ knownShS +withKnownShS :: forall sh r. ShS sh -> (KnownShS sh => r) -> r +withKnownShS sh = withDict @(KnownShS sh) sh + shsKnownShS :: ShS sh -> Dict KnownShS sh shsKnownShS ZSS = Dict shsKnownShS (SNat :$$ sh) | Dict <- shsKnownShS sh = Dict -- cgit v1.2.3-70-g09d2