typelits-witnesses 0.1.2.0 → 0.1.3.0
raw patch · 2 files changed
+27/−7 lines, 2 filesdep ~base
Dependency ranges changed: base
Files
- src/GHC/TypeLits/List.hs +26/−6
- typelits-witnesses.cabal +1/−1
src/GHC/TypeLits/List.hs view
@@ -39,6 +39,7 @@ , someNatsVal , someNatsVal' , reifyNats+ , reifyNats' , sameNats -- ** Traversals , traverseNatList@@ -199,19 +200,36 @@ -- -- Essentially a continuation-style version of 'SomeNats'. ----- For compatability with 'reifyNat', be aware that this also produces--- @'KnownNat' n@s where @n@ is negative, without complaining.+-- Be aware that this also produces @'KnownNat' n@s where @n@ is negative,+-- without complaining. To be consistent, within the library, this+-- /should/ be called @reifyNatsPos@; however, the naming choice is for+-- consistency with 'reifyNat' from the /reflections/ package. Use+-- 'reifyNats'' for a "safe" version. reifyNats :: [Integer] -> (forall ns. KnownNats ns => NatList ns -> r) -> r reifyNats [] f = f ØNL reifyNats (n:ns) f = reifyNat n $ \m -> reifyNats ns $ \ms -> f (m :<# ms) +-- | "Safe" version of 'reifyNats', which will only run the continuation if+-- every 'Integer' in the list is non-negative. If not, then returns+-- the given "default" value instead.+reifyNats'+ :: [Integer]+ -> r+ -> (forall ns. KnownNats ns => NatList ns -> r)+ -> r+reifyNats' ns d f =+ case someNatsVal ns of+ Just (SomeNats ms) -> f ms+ Nothing -> d++ -- | Like 'someNatsVal', but will also go ahead and produce 'KnownNat's -- whose integer values are negative. It won't ever error on producing -- them, but extra care must be taken when using the produced 'SomeNat's.-someNatsVal' :: [Integer] -> SomeNats-someNatsVal' ns = reifyNats ns SomeNats+someNatsValPos :: [Integer] -> SomeNats+someNatsValPos ns = reifyNats ns SomeNats -- | Get evidence that the two 'KnownNats' lists are actually the "same" -- list of 'Nat's (that they were instantiated with the same numbers).@@ -222,7 +240,7 @@ -- case 'sameNats' ns ms of -- Just 'Refl' -> -- in this branch, GHC recognizes that the two ['Nat']s -- -- are the same.--- Nothing -> -- in this branch, they aren't+-- Nothing -> -- in this branch, they aren't -- @ sameNats :: (KnownNats ns, KnownNats ms)@@ -380,6 +398,7 @@ reifySymbols ns $ \ms -> f (m :<$ ms) + -- | Get evidence that the two 'KnownSymbols' lists are actually the "same" -- list of 'Symboles's (that they were instantiated with the same strings). --@@ -389,7 +408,7 @@ -- case 'sameSymbols' ns ms of -- Just 'Refl' -> -- in this branch, GHC recognizes that the -- -- two ['Symbol']s are the same--- Nothing -> -- in this branch, they aren't+-- Nothing -> -- in this branch, they aren't -- @ sameSymbols :: (KnownSymbols ns, KnownSymbols ms)@@ -409,3 +428,4 @@ Refl <- sameSymbol n m Refl <- sameSymbols ns' ms' return Refl+
typelits-witnesses.cabal view
@@ -1,5 +1,5 @@ name: typelits-witnesses-version: 0.1.2.0+version: 0.1.3.0 synopsis: Existential witnesses, singletons, and classes for operations on GHC TypeLits description: Provides witnesses for 'KnownNat' and 'KnownSymbol' instances for various operations on GHC TypeLits - in