-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Convert between strong and weak representations of types -- -- Please see README.md. @package strongweak @version 0.7.1 module Strongweak.Util.Text tshow :: Show a => a -> Text module Strongweak.Util.TypeNats natVal'' :: forall n. KnownNat n => Natural module Strongweak.Util.Typeable typeRep' :: forall a. Typeable a => TypeRep module Strongweak.Weaken -- | Weaken some a, relaxing certain invariants. -- -- See Strongweak for class design notes and laws. class Weaken a where { -- | The weakened type for some type. type Weak a :: Type; } -- | Weaken some a to its associated weak type Weaken -- a. weaken :: Weaken a => a -> Weak a -- | Lift a function on a weak type to the associated strong type by -- weakening first. liftWeakF :: Weaken a => (Weak a -> b) -> a -> b -- | Strength enumeration: is it strong, or weak? -- -- Primarily interesting at the type level (using DataKinds). data Strength Strong :: Strength Weak :: Strength -- | Get either the strong or weak representation of a type, depending on -- the type-level "switch" provided. -- -- This is intended to be used in data types that take a Strength -- type. Define your type using strong fields wrapped in SW s. -- You then get the weak representation for free, using the same -- definition. -- --
--   data A (s :: Strength) = A
--     { a1 :: SW s Word8
--     , a2 :: String }
--   
type family SW (s :: Strength) a :: Type -- | Track multiple levels of weakening. Silly thought I had, don't think -- it's useful. type family SWDepth (n :: Natural) a :: Type instance forall k (p :: k) a. Strongweak.Weaken.Weaken (Rerefined.Refine.Refined p a) instance forall k k1 (p :: k) (f :: k1 -> GHC.Types.Type) (a :: k1). Strongweak.Weaken.Weaken (Rerefined.Refine.Refined1 p f a) instance Strongweak.Weaken.Weaken (GHC.Base.NonEmpty a) instance Data.Vector.Generic.Base.Vector v a => Strongweak.Weaken.Weaken (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Strongweak.Weaken.Weaken (Data.Functor.Identity.Identity a) instance forall k a (b :: k). Strongweak.Weaken.Weaken (Data.Functor.Const.Const a b) instance Strongweak.Weaken.Weaken GHC.Word.Word8 instance Strongweak.Weaken.Weaken GHC.Word.Word16 instance Strongweak.Weaken.Weaken GHC.Word.Word32 instance Strongweak.Weaken.Weaken GHC.Word.Word64 instance Strongweak.Weaken.Weaken GHC.Int.Int8 instance Strongweak.Weaken.Weaken GHC.Int.Int16 instance Strongweak.Weaken.Weaken GHC.Int.Int32 instance Strongweak.Weaken.Weaken GHC.Int.Int64 instance Strongweak.Weaken.Weaken a => Strongweak.Weaken.Weaken [a] instance (Strongweak.Weaken.Weaken a, Strongweak.Weaken.Weaken b) => Strongweak.Weaken.Weaken (a, b) instance (Strongweak.Weaken.Weaken a, Strongweak.Weaken.Weaken b) => Strongweak.Weaken.Weaken (Data.Either.Either a b) module Strongweak.Strengthen.Unsafe -- | Unsafely transform a Weaken a to an a, -- without asserting invariants. -- -- Naturally, you must only even consider using this if you have a -- guarantee that your value is safe to treat as strong. -- -- For example, you may unsafely strengthen some Natural -- n into a Word8 by unsafely coercing the value, ignoring -- the possibility that n >= 255. -- -- What happens if it turns out you're lying to the computer and your -- weak value doesn't fit in its strong counterpart? That depends on the -- strengthen. -- -- -- -- See Strongweak for class design notes and laws. class Weaken a => UnsafeStrengthen a -- | Unsafely transform a Weaken a to its associated strong -- type a. unsafeStrengthen :: UnsafeStrengthen a => Weak a -> a instance forall k (p :: k) a. Strongweak.Strengthen.Unsafe.UnsafeStrengthen (Rerefined.Refine.Refined p a) instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen (GHC.Base.NonEmpty a) instance Data.Vector.Generic.Base.Vector v a => Strongweak.Strengthen.Unsafe.UnsafeStrengthen (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen (Data.Functor.Identity.Identity a) instance forall k a (b :: k). Strongweak.Strengthen.Unsafe.UnsafeStrengthen (Data.Functor.Const.Const a b) instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Word.Word8 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Word.Word16 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Word.Word32 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Word.Word64 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Int.Int8 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Int.Int16 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Int.Int32 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Int.Int64 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen a => Strongweak.Strengthen.Unsafe.UnsafeStrengthen [a] instance (Strongweak.Strengthen.Unsafe.UnsafeStrengthen a, Strongweak.Strengthen.Unsafe.UnsafeStrengthen b) => Strongweak.Strengthen.Unsafe.UnsafeStrengthen (a, b) instance (Strongweak.Strengthen.Unsafe.UnsafeStrengthen a, Strongweak.Strengthen.Unsafe.UnsafeStrengthen b) => Strongweak.Strengthen.Unsafe.UnsafeStrengthen (Data.Either.Either a b) module Strongweak.Strengthen -- | Attempt to strengthen some Weak a, asserting certain -- invariants. -- -- We take Weaken as a superclass in order to maintain strong/weak -- type pair consistency. We choose this dependency direction because we -- treat the strong type as the "canonical" one, so Weaken is the -- more natural (and straightforward) class to define. That does mean the -- instances for this class are a little confusingly worded. Alas. -- -- See Strongweak for class design notes and laws. class Weaken a => Strengthen a -- | Attempt to strengthen some Weak a to its associated -- strong type a. strengthen :: Strengthen a => Weak a -> Result a -- | Weaken a strong value, then strengthen it again. -- -- Potentially useful if you have previously used unsafeStrengthen -- and now wish to check the invariants. For example: -- --
--   >>> restrengthen $ unsafeStrengthen @(Vector 2 Natural) [0]
--   Failure ...
--   
restrengthen :: (Strengthen a, Weaken a) => a -> Result a type Result = Validation StrengthenFailure -- | Strengthen one numeric type into another. -- -- n must be "wider" than m. -- -- FiniteBits m and Show n are for error -- printing. We're forced to Show n because -- linear-text-builder can't print unbounded integrals. PR: -- https://github.com/Bodigrim/linear-builder/pull/20 strengthenBounded :: forall m n. (Typeable n, Integral n, Show n, Typeable m, Integral m, Bounded m, FiniteBits m) => n -> Result m -- | A failure encountered during strengthening. data StrengthenFailure StrengthenFailure :: [Builder] -> [(Builder, StrengthenFailure)] -> StrengthenFailure -- | Detail on strengthen failure. -- -- We use a list here for the cases where you want multiple lines of -- detail. Separating with a newline would make prettifying later harder, -- so we delay. [strengthenFailDetail] :: StrengthenFailure -> [Builder] -- | Indexed. [strengthenFailInner] :: StrengthenFailure -> [(Builder, StrengthenFailure)] failStrengthen1 :: [Builder] -> Result a failStrengthen :: [Builder] -> [(Builder, StrengthenFailure)] -> Result a -- | The weakened type for some type. type Weak a :: Type instance GHC.Show.Show Strongweak.Strengthen.StrengthenFailure instance forall k (p :: k) a. Rerefined.Predicate.Refine p a => Strongweak.Strengthen.Strengthen (Rerefined.Refine.Refined p a) instance forall k k1 (p :: k) (f :: k1 -> GHC.Types.Type) (a :: k1). Rerefined.Predicate.Refine1 p f => Strongweak.Strengthen.Strengthen (Rerefined.Refine.Refined1 p f a) instance Strongweak.Strengthen.Strengthen (GHC.Base.NonEmpty a) instance (Data.Vector.Generic.Base.Vector v a, GHC.TypeNats.KnownNat n) => Strongweak.Strengthen.Strengthen (Data.Vector.Generic.Sized.Internal.Vector v n a) instance Strongweak.Strengthen.Strengthen (Data.Functor.Identity.Identity a) instance forall k a (b :: k). Strongweak.Strengthen.Strengthen (Data.Functor.Const.Const a b) instance Strongweak.Strengthen.Strengthen GHC.Word.Word8 instance Strongweak.Strengthen.Strengthen GHC.Word.Word16 instance Strongweak.Strengthen.Strengthen GHC.Word.Word32 instance Strongweak.Strengthen.Strengthen GHC.Word.Word64 instance Strongweak.Strengthen.Strengthen GHC.Int.Int8 instance Strongweak.Strengthen.Strengthen GHC.Int.Int16 instance Strongweak.Strengthen.Strengthen GHC.Int.Int32 instance Strongweak.Strengthen.Strengthen GHC.Int.Int64 instance Strongweak.Strengthen.Strengthen a => Strongweak.Strengthen.Strengthen [a] instance (Strongweak.Strengthen.Strengthen l, Strongweak.Strengthen.Strengthen r) => Strongweak.Strengthen.Strengthen (l, r) instance (Strongweak.Strengthen.Strengthen a, Strongweak.Strengthen.Strengthen b) => Strongweak.Strengthen.Strengthen (Data.Either.Either a b) -- | strengthen over generic representations. -- -- As with base instances, generic strengthening collates all failures -- rather than short-circuiting on the first failure. Failures are -- annotated with precise information describing where the failure -- occurred: -- -- module Strongweak.Strengthen.Generic -- | Strengthen a value generically. -- -- The weak and strong types must be compatible. See -- Generic for the definition of compatibility in this context. strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Result s -- | Generic strengthening at the datatype level. class GStrengthenD w s gstrengthenD :: GStrengthenD w s => w p -> Result (s p) -- | Generic strengthening at the constructor sum level. class GStrengthenC (wdn :: Symbol) (sdn :: Symbol) w s gstrengthenC :: GStrengthenC wdn sdn w s => w p -> Result (s p) class ReifyCstrs (ld :: Symbol) (lc :: Symbol) (rd :: Symbol) (rc :: Symbol) reifyCstrs :: ReifyCstrs ld lc rd rc => Builder -- | Generic strengthening at the constructor level. class GStrengthenS (i :: Natural) w s gstrengthenS :: GStrengthenS i w s => w p -> Validation [(Builder, StrengthenFailure)] (s p) class ReifySelector (i :: Natural) (l :: Maybe Symbol) (r :: Maybe Symbol) reifySelector :: ReifySelector i l r => Builder (.>) :: (a -> b) -> (b -> c) -> a -> c type family ProdArity (f :: k -> Type) :: Natural instance forall k (i :: GHC.Num.Natural.Natural) (wl :: k -> GHC.Types.Type) (sl :: k -> GHC.Types.Type) (wr :: k -> GHC.Types.Type) (sr :: k -> GHC.Types.Type). (Strongweak.Strengthen.Generic.GStrengthenS i wl sl, Strongweak.Strengthen.Generic.GStrengthenS (i GHC.TypeNats.+ Strongweak.Strengthen.Generic.ProdArity wl) wr sr) => Strongweak.Strengthen.Generic.GStrengthenS i (wl GHC.Generics.:*: wr) (sl GHC.Generics.:*: sr) instance (Strongweak.Weaken.Weak s GHC.Types.~ w, Strongweak.Strengthen.Strengthen s, Strongweak.Strengthen.Generic.ReifySelector i wmr smr) => Strongweak.Strengthen.Generic.GStrengthenS i (GHC.Generics.S1 ('GHC.Generics.MetaSel wmr _wms2 _wms3 _wms4) (GHC.Generics.Rec0 w)) (GHC.Generics.S1 ('GHC.Generics.MetaSel smr _sms2 _sms3 _sms4) (GHC.Generics.Rec0 s)) instance (GHC.TypeNats.KnownNat i, GHC.TypeLits.KnownSymbol lnm) => Strongweak.Strengthen.Generic.ReifySelector i ('GHC.Maybe.Just lnm) ('GHC.Maybe.Just lnm) instance (GHC.TypeNats.KnownNat i, GHC.TypeLits.KnownSymbol lnm, GHC.TypeLits.KnownSymbol rnm) => Strongweak.Strengthen.Generic.ReifySelector i ('GHC.Maybe.Just lnm) ('GHC.Maybe.Just rnm) instance GHC.TypeNats.KnownNat i => Strongweak.Strengthen.Generic.ReifySelector i 'GHC.Maybe.Nothing 'GHC.Maybe.Nothing instance (GHC.TypeNats.KnownNat i, GHC.TypeLits.KnownSymbol lnm) => Strongweak.Strengthen.Generic.ReifySelector i ('GHC.Maybe.Just lnm) 'GHC.Maybe.Nothing instance (GHC.TypeNats.KnownNat i, GHC.TypeLits.KnownSymbol rnm) => Strongweak.Strengthen.Generic.ReifySelector i 'GHC.Maybe.Nothing ('GHC.Maybe.Just rnm) instance forall k (w :: k -> GHC.Types.Type) (s :: k -> GHC.Types.Type) (wcd :: GHC.Types.Symbol) (wcn :: GHC.Types.Symbol) (scd :: GHC.Types.Symbol) (scn :: GHC.Types.Symbol) (_wmc2 :: GHC.Generics.FixityI) (_wmc3 :: GHC.Types.Bool) (_smc2 :: GHC.Generics.FixityI) (_smc3 :: GHC.Types.Bool). (Strongweak.Strengthen.Generic.GStrengthenS 0 w s, Strongweak.Strengthen.Generic.ReifyCstrs wcd wcn scd scn) => Strongweak.Strengthen.Generic.GStrengthenC wcd scd (GHC.Generics.C1 ('GHC.Generics.MetaCons wcn _wmc2 _wmc3) w) (GHC.Generics.C1 ('GHC.Generics.MetaCons scn _smc2 _smc3) s) instance Strongweak.Strengthen.Generic.GStrengthenS i GHC.Generics.U1 GHC.Generics.U1 instance Strongweak.Strengthen.Generic.GStrengthenS i (GHC.Generics.S1 ('GHC.Generics.MetaSel _wms1 _wms2 _wms3 _wms4) (GHC.Generics.Rec0 a)) (GHC.Generics.S1 ('GHC.Generics.MetaSel _sms1 _sms2 _sms3 _sms4) (GHC.Generics.Rec0 a)) instance (GHC.TypeLits.KnownSymbol d, GHC.TypeLits.KnownSymbol c) => Strongweak.Strengthen.Generic.ReifyCstrs d c d c instance (GHC.TypeLits.KnownSymbol ld, GHC.TypeLits.KnownSymbol lc, GHC.TypeLits.KnownSymbol rd, GHC.TypeLits.KnownSymbol rc) => Strongweak.Strengthen.Generic.ReifyCstrs ld lc rd rc instance forall k (wdn :: GHC.Types.Symbol) (sdn :: GHC.Types.Symbol) (w :: k -> GHC.Types.Type) (s :: k -> GHC.Types.Type) (_wmd2 :: GHC.Types.Symbol) (_wmd3 :: GHC.Types.Symbol) (_wmd4 :: GHC.Types.Bool) (_smd2 :: GHC.Types.Symbol) (_smd3 :: GHC.Types.Symbol) (_smd4 :: GHC.Types.Bool). Strongweak.Strengthen.Generic.GStrengthenC wdn sdn w s => Strongweak.Strengthen.Generic.GStrengthenD (GHC.Generics.D1 ('GHC.Generics.MetaData wdn _wmd2 _wmd3 _wmd4) w) (GHC.Generics.D1 ('GHC.Generics.MetaData sdn _smd2 _smd3 _smd4) s) instance Strongweak.Strengthen.Generic.GStrengthenC wdn sdn GHC.Generics.V1 GHC.Generics.V1 instance forall k (wdn :: GHC.Types.Symbol) (sdn :: GHC.Types.Symbol) (wl :: k -> GHC.Types.Type) (sl :: k -> GHC.Types.Type) (wr :: k -> GHC.Types.Type) (sr :: k -> GHC.Types.Type). (Strongweak.Strengthen.Generic.GStrengthenC wdn sdn wl sl, Strongweak.Strengthen.Generic.GStrengthenC wdn sdn wr sr) => Strongweak.Strengthen.Generic.GStrengthenC wdn sdn (wl GHC.Generics.:+: wr) (sl GHC.Generics.:+: sr) -- | Main import module for basic use. -- -- For defining Strengthen instances, import -- Strongweak.Strengthen. module Strongweak -- | Weaken some a, relaxing certain invariants. -- -- See Strongweak for class design notes and laws. class Weaken a where { -- | The weakened type for some type. type Weak a :: Type; } -- | Weaken some a to its associated weak type Weaken -- a. weaken :: Weaken a => a -> Weak a -- | Attempt to strengthen some Weak a, asserting certain -- invariants. -- -- We take Weaken as a superclass in order to maintain strong/weak -- type pair consistency. We choose this dependency direction because we -- treat the strong type as the "canonical" one, so Weaken is the -- more natural (and straightforward) class to define. That does mean the -- instances for this class are a little confusingly worded. Alas. -- -- See Strongweak for class design notes and laws. class Weaken a => Strengthen a -- | Attempt to strengthen some Weak a to its associated -- strong type a. strengthen :: Strengthen a => Weak a -> Result a -- | Lift a function on a weak type to the associated strong type by -- weakening first. liftWeakF :: Weaken a => (Weak a -> b) -> a -> b -- | Strength enumeration: is it strong, or weak? -- -- Primarily interesting at the type level (using DataKinds). data Strength Strong :: Strength Weak :: Strength -- | Get either the strong or weak representation of a type, depending on -- the type-level "switch" provided. -- -- This is intended to be used in data types that take a Strength -- type. Define your type using strong fields wrapped in SW s. -- You then get the weak representation for free, using the same -- definition. -- --
--   data A (s :: Strength) = A
--     { a1 :: SW s Word8
--     , a2 :: String }
--   
type family SW (s :: Strength) a :: Type -- | weaken over generic representations. module Strongweak.Weaken.Generic -- | Weaken a value generically. -- -- The weak and strong types must be compatible. See -- Generic for the definition of compatibility in this context. weakenGeneric :: (Generic s, Generic w, GWeaken (Rep s) (Rep w)) => s -> w class GWeaken s w gweaken :: GWeaken s w => s p -> w p instance forall k (s :: k -> GHC.Types.Type) (w :: k -> GHC.Types.Type) is (ms :: GHC.Generics.Meta) iw (mw :: GHC.Generics.Meta). Strongweak.Weaken.Generic.GWeaken s w => Strongweak.Weaken.Generic.GWeaken (GHC.Generics.M1 is ms s) (GHC.Generics.M1 iw mw w) instance Strongweak.Weaken.Generic.GWeaken GHC.Generics.V1 GHC.Generics.V1 instance Strongweak.Weaken.Generic.GWeaken GHC.Generics.U1 GHC.Generics.U1 instance Strongweak.Weaken.Generic.GWeaken (GHC.Generics.Rec0 s) (GHC.Generics.Rec0 s) instance (Strongweak.Weaken.Weaken s, Strongweak.Weaken.Weak s GHC.Types.~ w) => Strongweak.Weaken.Generic.GWeaken (GHC.Generics.Rec0 s) (GHC.Generics.Rec0 w) instance forall k (ls :: k -> GHC.Types.Type) (lw :: k -> GHC.Types.Type) (rs :: k -> GHC.Types.Type) (rw :: k -> GHC.Types.Type). (Strongweak.Weaken.Generic.GWeaken ls lw, Strongweak.Weaken.Generic.GWeaken rs rw) => Strongweak.Weaken.Generic.GWeaken (ls GHC.Generics.:*: rs) (lw GHC.Generics.:*: rw) instance forall k (ls :: k -> GHC.Types.Type) (lw :: k -> GHC.Types.Type) (rs :: k -> GHC.Types.Type) (rw :: k -> GHC.Types.Type). (Strongweak.Weaken.Generic.GWeaken ls lw, Strongweak.Weaken.Generic.GWeaken rs rw) => Strongweak.Weaken.Generic.GWeaken (ls GHC.Generics.:+: rs) (lw GHC.Generics.:+: rw) -- | Generic strengthen and weaken. module Strongweak.Generic -- | Weaken a value generically. -- -- The weak and strong types must be compatible. See -- Generic for the definition of compatibility in this context. weakenGeneric :: (Generic s, Generic w, GWeaken (Rep s) (Rep w)) => s -> w -- | Strengthen a value generically. -- -- The weak and strong types must be compatible. See -- Generic for the definition of compatibility in this context. strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Result s -- | DerivingVia wrapper for strongweak instances. -- -- We can't use Generically conveniently because we need to talk -- about two data types, not one -- we would have to do something like -- Generically (Tagged w s), which is ugly. So -- we instead define our own adorable little "via type" here! -- -- Use like so: -- --
--   data XYZ (s :: Strength) = XYZ
--     { xyz1 :: SW s Word8
--     , xyz2 :: Word8
--     , xyz3 :: ()
--     } deriving stock Generic
--   deriving via (GenericallySW (XYZ 'Strong) (XYZ 'Weak)) instance Weaken (XYZ 'Strong)
--   deriving via (GenericallySW (XYZ 'Strong) (XYZ 'Weak)) instance Strengthen (XYZ 'Strong)
--   
-- -- TODO can't figure out a way around multiple standalone deriving -- declarations :( -- -- TODO maybe GenericallySW1? but even so instances differ between weaken -- and strengthen (weaken needs nothing) so it's kinda better this way. -- :) newtype GenericallySW s (w :: Type) GenericallySW :: s -> GenericallySW s (w :: Type) [unGenericallySW] :: GenericallySW s (w :: Type) -> s instance (GHC.Generics.Generic s, GHC.Generics.Generic w, Strongweak.Weaken.Generic.GWeaken (GHC.Generics.Rep s) (GHC.Generics.Rep w)) => Strongweak.Weaken.Weaken (Strongweak.Generic.GenericallySW s w) instance (GHC.Generics.Generic s, GHC.Generics.Generic w, Strongweak.Strengthen.Generic.GStrengthenD (GHC.Generics.Rep w) (GHC.Generics.Rep s), Strongweak.Weaken.Weaken (Strongweak.Generic.GenericallySW s w)) => Strongweak.Strengthen.Strengthen (Strongweak.Generic.GenericallySW s w)