-- 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.2.0 module Strongweak.SW data Strength Strong :: Strength Weak :: Strength -- | Obtain the weak representation of the given type. type family Weak (a :: Type) :: Type -- | Obtain either the strong or weak representation of a type, depending -- on the type-level strength "switch" provided. -- -- This is intended to be used in data types that take a Strength -- type. Define your type using strong fields wrapped in Switch -- s. You then get the weak representation for free, using the same -- definition. -- --
--   data A (s :: Strength) = A
--     { aField1 :: Switch s Word8
--     , aField2 :: String }
--   
type family SW (s :: Strength) a :: Type module Strongweak.Strengthen -- | Any w can be "strengthened" into an s by asserting -- some properties. -- -- For example, you may strengthen some Natural n into a -- Word8 by asserting 0 <= n <= 255. -- -- Note that we restrict strengthened types to having only one -- corresponding weak representation using functional dependencies. class Strengthen w s | s -> w strengthen :: Strengthen w s => w -> Validation (NonEmpty StrengthenError) s -- | strengthen with reordered type variables for more convenient -- visible type application. strengthen' :: forall s w. Strengthen w s => w -> Validation (NonEmpty StrengthenError) s -- | Strengthen error data type. Don't use these constructors directly, use -- the existing helper functions. -- -- Field indices are from 0 in the respective constructor. Field names -- are provided if present. data StrengthenError StrengthenErrorBase :: String -> String -> String -> String -> StrengthenError StrengthenErrorField :: String -> String -> String -> String -> Natural -> Maybe String -> Natural -> Maybe String -> NonEmpty StrengthenError -> StrengthenError strengthenErrorPretty :: NonEmpty StrengthenError -> Doc a strengthenErrorBase :: forall s w. (Typeable w, Show w, Typeable s) => w -> String -> Validation (NonEmpty StrengthenError) s strengthenBounded :: forall b n. (Integral b, Bounded b, Show b, Typeable b, Integral n, Show n, Typeable n) => n -> Validation (NonEmpty StrengthenError) b instance GHC.Classes.Eq Strongweak.Strengthen.StrengthenError instance Strongweak.Strengthen.Strengthen w s => Strongweak.Strengthen.Strengthen [w] [s] instance (GHC.TypeNats.KnownNat n, Data.Typeable.Internal.Typeable a, GHC.Show.Show a) => Strongweak.Strengthen.Strengthen [a] (Data.Vector.Sized.Vector n a) instance (Refined.Predicate p a, Data.Typeable.Internal.Typeable p, Data.Typeable.Internal.Typeable a, GHC.Show.Show a) => Strongweak.Strengthen.Strengthen a (Refined.Unsafe.Type.Refined p a) instance Strongweak.Strengthen.Strengthen GHC.Num.Natural.Natural GHC.Word.Word8 instance Strongweak.Strengthen.Strengthen GHC.Num.Natural.Natural GHC.Word.Word16 instance Strongweak.Strengthen.Strengthen GHC.Num.Natural.Natural GHC.Word.Word32 instance Strongweak.Strengthen.Strengthen GHC.Num.Natural.Natural GHC.Word.Word64 instance Strongweak.Strengthen.Strengthen GHC.Num.Integer.Integer GHC.Int.Int8 instance Strongweak.Strengthen.Strengthen GHC.Num.Integer.Integer GHC.Int.Int16 instance Strongweak.Strengthen.Strengthen GHC.Num.Integer.Integer GHC.Int.Int32 instance Strongweak.Strengthen.Strengthen GHC.Num.Integer.Integer GHC.Int.Int64 instance GHC.Show.Show Strongweak.Strengthen.StrengthenError instance Prettyprinter.Internal.Pretty Strongweak.Strengthen.StrengthenError -- | Strengthening for generic data types. -- -- The generic derivation is split into 3 classes, each dealing with a -- different layer of a generic Haskell data type: datatype (D), -- constructor (C) and selector (S). At each point, we gather up -- information about the type and push on. Strengthening occurs at -- selectors. If a strengthening fails, the gathered information is -- pushed into an error that wraps the original error. module Strongweak.Generic.Strengthen strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Validation (NonEmpty StrengthenError) s class GStrengthenD w s gstrengthenD :: GStrengthenD w s => w p -> Validation (NonEmpty StrengthenError) (s p) class GStrengthenC w s gstrengthenC :: GStrengthenC w s => String -> String -> w p -> Validation (NonEmpty StrengthenError) (s p) class GStrengthenS w s gstrengthenS :: GStrengthenS w s => String -> String -> String -> String -> Natural -> w p -> (Natural, Validation (NonEmpty StrengthenError) (s p)) -- | Get the record name for a selector if present. -- -- On the type level, a 'Maybe Symbol' is stored for record names. But -- the reification is done using fromMaybe "". So we have to -- inspect the resulting string to determine whether the field uses -- record syntax or not. (Silly.) selName'' :: forall s. Selector s => Maybe String -- | conName without the value (only used as a proxy). Lets us push -- our undefineds into one place. conName' :: forall c. Constructor c => String -- | datatypeName without the value (only used as a proxy). Lets us -- push our undefineds into one place. datatypeName' :: forall d. Datatype d => String -- | selName without the value (only used as a proxy). Lets us push -- our undefineds into one place. selName' :: forall s. Selector s => String instance forall k (w :: k -> *) (s :: k -> *) (cw :: GHC.Generics.Meta) (cs :: GHC.Generics.Meta). (Strongweak.Generic.Strengthen.GStrengthenS w s, GHC.Generics.Constructor cw, GHC.Generics.Constructor cs) => Strongweak.Generic.Strengthen.GStrengthenC (GHC.Generics.C1 cw w) (GHC.Generics.C1 cs s) instance Strongweak.Generic.Strengthen.GStrengthenS GHC.Generics.U1 GHC.Generics.U1 instance Strongweak.Generic.Strengthen.GStrengthenS (GHC.Generics.S1 mw (GHC.Generics.Rec0 w)) (GHC.Generics.S1 ms (GHC.Generics.Rec0 w)) instance (Strongweak.Strengthen.Strengthen w s, GHC.Generics.Selector mw, GHC.Generics.Selector ms) => Strongweak.Generic.Strengthen.GStrengthenS (GHC.Generics.S1 mw (GHC.Generics.Rec0 w)) (GHC.Generics.S1 ms (GHC.Generics.Rec0 s)) instance forall k (lw :: k -> *) (ls :: k -> *) (rw :: k -> *) (rs :: k -> *). (Strongweak.Generic.Strengthen.GStrengthenS lw ls, Strongweak.Generic.Strengthen.GStrengthenS rw rs) => Strongweak.Generic.Strengthen.GStrengthenS (lw GHC.Generics.:*: rw) (ls GHC.Generics.:*: rs) instance forall k (w :: k -> *) (s :: k -> *) (dw :: GHC.Generics.Meta) (ds :: GHC.Generics.Meta). (Strongweak.Generic.Strengthen.GStrengthenC w s, GHC.Generics.Datatype dw, GHC.Generics.Datatype ds) => Strongweak.Generic.Strengthen.GStrengthenD (GHC.Generics.D1 dw w) (GHC.Generics.D1 ds s) instance Strongweak.Generic.Strengthen.GStrengthenC GHC.Generics.V1 GHC.Generics.V1 instance forall k (lw :: k -> *) (ls :: k -> *) (rw :: k -> *) (rs :: k -> *). (Strongweak.Generic.Strengthen.GStrengthenC lw ls, Strongweak.Generic.Strengthen.GStrengthenC rw rs) => Strongweak.Generic.Strengthen.GStrengthenC (lw GHC.Generics.:+: rw) (ls GHC.Generics.:+: rs) module Strongweak.Strengthen.Unsafe -- | Any w can be unsafely "strengthened" into an s by -- pretending that we've asserted some properties. -- -- For example, you may unsafely strengthen some Natural -- n into a Word8 by unsafely coercing the value, -- ignoring the possibility that n >= 255. -- -- Currently, this class is more of a thought experiment than something -- to use. That is to say, do not use this. -- -- This typeclass should probably follow its big sis Strengthen. -- Only provide UnsafeStrengthen instances for types that have -- similar Strengthen instances. class UnsafeStrengthen w s | s -> w unsafeStrengthen :: UnsafeStrengthen w s => w -> s -- | unsafeStrengthen with reordered type variables for more -- convenient visible type application. unsafeStrengthen' :: forall s w. UnsafeStrengthen w s => w -> s instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen w s => Strongweak.Strengthen.Unsafe.UnsafeStrengthen [w] [s] instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen [a] (Data.Vector.Sized.Vector n a) instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen a (Refined.Unsafe.Type.Refined p a) instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Natural.Natural GHC.Word.Word8 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Natural.Natural GHC.Word.Word16 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Natural.Natural GHC.Word.Word32 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Natural.Natural GHC.Word.Word64 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Integer.Integer GHC.Int.Int8 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Integer.Integer GHC.Int.Int16 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Integer.Integer GHC.Int.Int32 instance Strongweak.Strengthen.Unsafe.UnsafeStrengthen GHC.Num.Integer.Integer GHC.Int.Int64 module Strongweak.Weaken -- | Any s can be "weakened" into a w. -- -- For example, you may weaken a Word8 into a Natural. -- -- Note that we restrict strengthened types to having only one -- corresponding weak representation using functional dependencies. class Weaken s w | s -> w weaken :: Weaken s w => s -> w instance Strongweak.Weaken.Weaken s w => Strongweak.Weaken.Weaken [s] [w] instance Strongweak.Weaken.Weaken (Data.Vector.Sized.Vector n a) [a] instance Strongweak.Weaken.Weaken (Refined.Unsafe.Type.Refined p a) a instance Strongweak.Weaken.Weaken GHC.Word.Word8 GHC.Num.Natural.Natural instance Strongweak.Weaken.Weaken GHC.Word.Word16 GHC.Num.Natural.Natural instance Strongweak.Weaken.Weaken GHC.Word.Word32 GHC.Num.Natural.Natural instance Strongweak.Weaken.Weaken GHC.Word.Word64 GHC.Num.Natural.Natural instance Strongweak.Weaken.Weaken GHC.Int.Int8 GHC.Num.Integer.Integer instance Strongweak.Weaken.Weaken GHC.Int.Int16 GHC.Num.Integer.Integer instance Strongweak.Weaken.Weaken GHC.Int.Int32 GHC.Num.Integer.Integer instance Strongweak.Weaken.Weaken GHC.Int.Int64 GHC.Num.Integer.Integer -- | Weakening for generic data types. module Strongweak.Generic.Weaken 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 -> *) (w :: k -> *) is (ms :: GHC.Generics.Meta) iw (mw :: GHC.Generics.Meta). Strongweak.Generic.Weaken.GWeaken s w => Strongweak.Generic.Weaken.GWeaken (GHC.Generics.M1 is ms s) (GHC.Generics.M1 iw mw w) instance Strongweak.Generic.Weaken.GWeaken GHC.Generics.V1 GHC.Generics.V1 instance Strongweak.Generic.Weaken.GWeaken GHC.Generics.U1 GHC.Generics.U1 instance Strongweak.Generic.Weaken.GWeaken (GHC.Generics.Rec0 s) (GHC.Generics.Rec0 s) instance Strongweak.Weaken.Weaken s w => Strongweak.Generic.Weaken.GWeaken (GHC.Generics.Rec0 s) (GHC.Generics.Rec0 w) instance forall k (ls :: k -> *) (lw :: k -> *) (rs :: k -> *) (rw :: k -> *). (Strongweak.Generic.Weaken.GWeaken ls lw, Strongweak.Generic.Weaken.GWeaken rs rw) => Strongweak.Generic.Weaken.GWeaken (ls GHC.Generics.:*: rs) (lw GHC.Generics.:*: rw) instance forall k (ls :: k -> *) (lw :: k -> *) (rs :: k -> *) (rw :: k -> *). (Strongweak.Generic.Weaken.GWeaken ls lw, Strongweak.Generic.Weaken.GWeaken rs rw) => Strongweak.Generic.Weaken.GWeaken (ls GHC.Generics.:+: rs) (lw GHC.Generics.:+: rw) module Strongweak.Generic weakenGeneric :: (Generic s, Generic w, GWeaken (Rep s) (Rep w)) => s -> w strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Validation (NonEmpty StrengthenError) s module Strongweak -- | Weaken and re-strengthen a strong value. -- -- In correct operation, restrengthen === Right. If your value -- was strengthened incorrectly, or perhaps you cheated via -- UnsafeStrengthen, this may not be the case. For example: -- --
--   >>> restrengthen $ unsafeStrengthen' @(Vector 2 Natural) [0]
--   Failure ...
--   
restrengthen :: forall w s. (Weaken s w, Strengthen w s) => s -> Validation (NonEmpty StrengthenError) s module Strongweak.Example data Ex1D (s :: Strength) Ex1C :: SW s Word8 -> SW s (Refined (LessThan 100) Natural) -> Ex1D (s :: Strength) [ex1f1] :: Ex1D (s :: Strength) -> SW s Word8 [ex1f2] :: Ex1D (s :: Strength) -> SW s (Refined (LessThan 100) Natural) data Ex2D (s :: Strength) Ex2C :: Ex1D s -> SW s Word8 -> Ex2D (s :: Strength) [ex2f1] :: Ex2D (s :: Strength) -> Ex1D s [ex2f2] :: Ex2D (s :: Strength) -> SW s Word8 ex1w :: Ex1D 'Weak ex2w :: Ex2D 'Weak data ExVoid (s :: Strength) data ExUnit (s :: Strength) ExUnit :: ExUnit (s :: Strength) instance GHC.Generics.Generic (Strongweak.Example.Ex1D s) instance GHC.Generics.Generic (Strongweak.Example.Ex2D s) instance GHC.Generics.Generic (Strongweak.Example.ExVoid s) instance GHC.Generics.Generic (Strongweak.Example.ExUnit s) instance GHC.Show.Show (Strongweak.Example.Ex1D 'Strongweak.SW.Strong) instance GHC.Show.Show (Strongweak.Example.Ex1D 'Strongweak.SW.Weak) instance GHC.Show.Show (Strongweak.Example.Ex2D 'Strongweak.SW.Strong) instance GHC.Show.Show (Strongweak.Example.Ex2D 'Strongweak.SW.Weak) instance Strongweak.Weaken.Weaken (Strongweak.Example.ExUnit 'Strongweak.SW.Strong) (Strongweak.Example.ExUnit 'Strongweak.SW.Weak) instance Strongweak.Strengthen.Strengthen (Strongweak.Example.ExUnit 'Strongweak.SW.Weak) (Strongweak.Example.ExUnit 'Strongweak.SW.Strong) instance Strongweak.Weaken.Weaken (Strongweak.Example.ExVoid 'Strongweak.SW.Strong) (Strongweak.Example.ExVoid 'Strongweak.SW.Weak) instance Strongweak.Strengthen.Strengthen (Strongweak.Example.ExVoid 'Strongweak.SW.Weak) (Strongweak.Example.ExVoid 'Strongweak.SW.Strong) instance Strongweak.Weaken.Weaken (Strongweak.Example.Ex2D 'Strongweak.SW.Strong) (Strongweak.Example.Ex2D 'Strongweak.SW.Weak) instance Strongweak.Strengthen.Strengthen (Strongweak.Example.Ex2D 'Strongweak.SW.Weak) (Strongweak.Example.Ex2D 'Strongweak.SW.Strong) instance Strongweak.Weaken.Weaken (Strongweak.Example.Ex1D 'Strongweak.SW.Strong) (Strongweak.Example.Ex1D 'Strongweak.SW.Weak) instance Strongweak.Strengthen.Strengthen (Strongweak.Example.Ex1D 'Strongweak.SW.Weak) (Strongweak.Example.Ex1D 'Strongweak.SW.Strong)