generic-labels-0.1.0.1: Generically extract and replace collections of record fields
Safe HaskellNone
LanguageHaskell2010

Data.Generic.Labels.Internal.Errors

Description

Internal module providing custom type errors for invalid uses of Adapt, inject, project.

Consider for instance trying to project a source record onto a smaller target record, but the source record is missing one of the fields:

missingField :: ( "a" := Bool, "c" := Double ) -> ( "c" := Double, "b" := Int )
missingField = project

Note that the source record is missing the "b" := Int field which is present in the target.

This results in the following error message:

  * No instance for
        Project
          ("b" := Float, "a" := Bool, "c" := Double)
          ("c" := Double, "b" := Int)
    The type being projected down is missing the following fields:
      - #b := Int
Synopsis

Documentation

type family AdaptLabelMessage lbl mb_argTy mb_optTy allTy where ... Source #

Throw an error message when encountering two distinct types with the same label.

Equations

AdaptLabelMessage _ Nothing Nothing ty = () :: Constraint 
AdaptLabelMessage _ (Just ty) Nothing ty = () :: Constraint 
AdaptLabelMessage _ Nothing (Just ty) ty = () :: Constraint 
AdaptLabelMessage _ (Just ty) (Just ty) ty = () :: Constraint 
AdaptLabelMessage lbl (Just a) Nothing b = TypeError ((((Text "Mismatched types at label #" :<>: Text lbl) :<>: Text ".") :$$: (Text " Expected type: " :<>: ShowType b)) :$$: (Text " Provided type: " :<>: ShowType a)) 
AdaptLabelMessage lbl Nothing (Just o) b = TypeError ((((Text "Mismatched types at label #" :<>: Text lbl) :<>: Text ".") :$$: (Text " Expected type: " :<>: ShowType b)) :$$: (Text " Optional type: " :<>: ShowType o)) 
AdaptLabelMessage lbl (Just a) (Just o) b = TypeError (((((Text "Mismatched types at label #" :<>: Text lbl) :<>: Text ".") :$$: (Text " Expected type: " :<>: ShowType b)) :$$: (Text " Provided type: " :<>: ShowType a)) :$$: (Text " Optional type: " :<>: ShowType o)) 

type family CheckAdapt args opt all where ... Source #

Throw an error message when an invalid use of Adapt is encountered: - a field of the destination is missing in the source, - a field that appears in both the source and destination appears more than once in either, - a Generic instance is missing.

Equations

CheckAdapt a a a = () :: Constraint 
CheckAdapt a opt a = () :: Constraint 
CheckAdapt (lbl := a) (lbl := o) (lbl := b) = (AdaptLabelMessage lbl (Just a) (Just o) b, a ~ b, o ~ b) 
CheckAdapt (lbl := a) opt (lbl := b) = (AdaptLabelMessage lbl (Just a) Nothing b, a ~ b) 
CheckAdapt (lbl1 := arg) (lbl2 := opt) all = (ProperAdapt arg opt all (CollectLeaves (S1 (MetaSel (Just lbl1) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 arg))) (CollectLeaves (S1 (MetaSel (Just lbl2) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 opt))) (CollectLeaves (Rep all)), ErrorIfAmbiguous (Rep all) (TypeError ((Text "No instance for " :<>: ShowType (Generic all)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt (lbl1 := arg) (lbl2 := opt) all)))) (() :: Constraint)) 
CheckAdapt (lbl := arg) opt all = (ProperAdapt arg opt all (CollectLeaves (S1 (MetaSel (Just lbl) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 arg))) (CollectLeaves (Rep opt)) (CollectLeaves (Rep all)), ErrorIfAmbiguous (Rep opt) (TypeError ((Text "No instance for " :<>: ShowType (Generic opt)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt (lbl := arg) opt all)))) (() :: Constraint), ErrorIfAmbiguous (Rep all) (TypeError ((Text "No instance for " :<>: ShowType (Generic all)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt (lbl := arg) opt all)))) (() :: Constraint)) 
CheckAdapt args (lbl := opt) all = (ProperAdapt args opt all (CollectLeaves (Rep args)) (CollectLeaves (S1 (MetaSel (Just lbl) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 opt))) (CollectLeaves (Rep all)), ErrorIfAmbiguous (Rep args) (TypeError ((Text "No instance for " :<>: ShowType (Generic args)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt args (lbl := opt) all)))) (() :: Constraint), ErrorIfAmbiguous (Rep all) (TypeError ((Text "No instance for " :<>: ShowType (Generic all)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt args (lbl := opt) all)))) (() :: Constraint)) 
CheckAdapt args opt all = (ProperAdapt args opt all (CollectLeaves (Rep args)) (CollectLeaves (Rep opt)) (CollectLeaves (Rep all)), ErrorIfAmbiguous (Rep args) (TypeError ((Text "No instance for " :<>: ShowType (Generic args)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt args opt all)))) (() :: Constraint), ErrorIfAmbiguous (Rep opt) (TypeError ((Text "No instance for " :<>: ShowType (Generic opt)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt args opt all)))) (() :: Constraint), ErrorIfAmbiguous (Rep all) (TypeError ((Text "No instance for " :<>: ShowType (Generic all)) :$$: (Text "arising from the constraint " :<>: ShowType (Adapt args opt all)))) (() :: Constraint)) 

type family CheckInject small big where ... Source #

Throw an error message when an invalid use of inject is encountered: - a field of the destination is missing in the source, - a field that appears in both the source and destination appears more than once in either, - a Generic instance is missing.

Equations

CheckInject a a = () :: Constraint 
CheckInject small big = (ProperInjection small big (CollectLeaves (Rep small)) (CollectLeaves (Rep big)), ErrorIfAmbiguous (Rep small) (TypeError ((Text "No instance for " :<>: ShowType (Generic small)) :$$: (Text "arising from the constraint " :<>: ShowType (Inject small big)))) (() :: Constraint), ErrorIfAmbiguous (Rep big) (TypeError ((Text "No instance for " :<>: ShowType (Generic big)) :$$: (Text "arising from the constraint " :<>: ShowType (Inject small big)))) (() :: Constraint)) 

type family CheckProject big small where ... Source #

Throw an error message when an invalid use of project is encountered: - a field of the destination is missing in the source, - a field that appears in both the source and destination appears more than once in either, - a Generic instance is missing.

Equations

CheckProject a a = () :: Constraint 
CheckProject big small = (ProperProjection big small (CollectLeaves (Rep big)) (CollectLeaves (Rep small)), ErrorIfAmbiguous (Rep big) (TypeError ((Text "No instance for " :<>: ShowType (Generic big)) :$$: (Text "arising from the constraint " :<>: ShowType (Project big small)))) (() :: Constraint), ErrorIfAmbiguous (Rep small) (TypeError ((Text "No instance for " :<>: ShowType (Generic small)) :$$: (Text "arising from the constraint " :<>: ShowType (Project big small)))) (() :: Constraint))