Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
strengthen
over generic representations.
Strengthen failures are annotated with precise information describing where the failure occurred: datatype name, constructor name, field index (and name if present). To achieve this, we split the generic derivation into 3 classes, each handling/"unwrapping" a different layer of the generic representation: datatype (D), constructor (C) and selector (S).
Synopsis
- strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Validation (NonEmpty StrengthenFail) s
- class GStrengthenD w s where
- gstrengthenD :: w p -> Validation (NonEmpty StrengthenFail) (s p)
- class GStrengthenC w s where
- gstrengthenC :: String -> String -> w p -> Validation (NonEmpty StrengthenFail) (s p)
- class GStrengthenS w s where
- gstrengthenS :: String -> String -> String -> String -> Natural -> w p -> (Natural, Validation (NonEmpty StrengthenFail) (s p))
- selName'' :: forall s. Selector s => Maybe String
- conName' :: forall c. Constructor c => String
- datatypeName' :: forall d. Datatype d => String
- selName' :: forall s. Selector s => String
Documentation
strengthenGeneric :: (Generic w, Generic s, GStrengthenD (Rep w) (Rep s)) => w -> Validation (NonEmpty StrengthenFail) s Source #
Strengthen a value generically.
The weak and strong types must be compatible. See Generic
for
the definition of compatibility in this context.
class GStrengthenD w s where Source #
Generic strengthening at the datatype level.
gstrengthenD :: w p -> Validation (NonEmpty StrengthenFail) (s p) Source #
Instances
(GStrengthenC w s, Datatype dw, Datatype ds) => GStrengthenD (D1 dw w :: k -> Type) (D1 ds s :: k -> Type) Source # | Enter a datatype, stripping its metadata wrapper. |
Defined in Strongweak.Generic.Strengthen gstrengthenD :: forall (p :: k0). D1 dw w p -> Validation (NonEmpty StrengthenFail) (D1 ds s p) Source # |
class GStrengthenC w s where Source #
Generic strengthening at the constructor sum level.
gstrengthenC :: String -> String -> w p -> Validation (NonEmpty StrengthenFail) (s p) Source #
Instances
GStrengthenC (V1 :: k -> Type) (V1 :: k -> Type) Source # | Nothing to do for empty datatypes. |
Defined in Strongweak.Generic.Strengthen gstrengthenC :: forall (p :: k0). String -> String -> V1 p -> Validation (NonEmpty StrengthenFail) (V1 p) Source # | |
(GStrengthenC lw ls, GStrengthenC rw rs) => GStrengthenC (lw :+: rw :: k -> Type) (ls :+: rs :: k -> Type) Source # | Strengthen sum types by casing and strengthening left or right. |
Defined in Strongweak.Generic.Strengthen gstrengthenC :: forall (p :: k0). String -> String -> (lw :+: rw) p -> Validation (NonEmpty StrengthenFail) ((ls :+: rs) p) Source # | |
(GStrengthenS w s, Constructor cw, Constructor cs) => GStrengthenC (C1 cw w :: k -> Type) (C1 cs s :: k -> Type) Source # | Enter a constructor, stripping its metadata wrapper. |
Defined in Strongweak.Generic.Strengthen gstrengthenC :: forall (p :: k0). String -> String -> C1 cw w p -> Validation (NonEmpty StrengthenFail) (C1 cs s p) Source # |
class GStrengthenS w s where Source #
Generic strengthening at the selector product level.
In order to calculate field indices, we return the current field index alongside the result. This way, the product case can strengthen the left branch, then increment the returned field index and use it for strengthening the right branch.
:: String | weak datatype name |
-> String | strong datatype name |
-> String | weak constructor name |
-> String | strong constructor name |
-> Natural | current field index (0, from left) |
-> w p | |
-> (Natural, Validation (NonEmpty StrengthenFail) (s p)) |
Instances
GStrengthenS (U1 :: k -> Type) (U1 :: k -> Type) Source # | Nothing to do for empty constructors. |
Defined in Strongweak.Generic.Strengthen gstrengthenS :: forall (p :: k0). String -> String -> String -> String -> Natural -> U1 p -> (Natural, Validation (NonEmpty StrengthenFail) (U1 p)) Source # | |
(GStrengthenS lw ls, GStrengthenS rw rs) => GStrengthenS (lw :*: rw :: k -> Type) (ls :*: rs :: k -> Type) Source # | Strengthen product types by strengthening left and right. This is ordered (left then right) in order to pass the field index along. |
Defined in Strongweak.Generic.Strengthen gstrengthenS :: forall (p :: k0). String -> String -> String -> String -> Natural -> (lw :*: rw) p -> (Natural, Validation (NonEmpty StrengthenFail) ((ls :*: rs) p)) Source # | |
(Strengthen s, Weak s ~ w, Selector mw, Selector ms) => GStrengthenS (S1 mw (Rec0 w) :: k -> Type) (S1 ms (Rec0 s) :: k -> Type) Source # | Strengthen a field using the existing |
Defined in Strongweak.Generic.Strengthen | |
GStrengthenS (S1 mw (Rec0 w) :: k -> Type) (S1 ms (Rec0 w) :: k -> Type) Source # | Special case: if source and target types are equal, copy the value through. |
Defined in Strongweak.Generic.Strengthen |
selName'' :: forall s. Selector s => Maybe String Source #
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.)
conName' :: forall c. Constructor c => String Source #
datatypeName' :: forall d. Datatype d => String Source #
datatypeName
without the value (only used as a proxy). Lets us push our
undefined
s into one place.