generic-constraints-1.1.1.1: Constraints via Generic

Safe HaskellSafe
LanguageHaskell2010

Generics.Constraints

Description

Write short and concise contexts based on generics.

Instead of writing boiler-plate standalone deriving clauses in the form of

deriving instance [Various Eq Constraints Here] => Instance Eq MyType

You can use

deriving instance Constraints MyType Eq => Eq MyType

And with the TemplateHaskell helpers makeDeriving and others, your declarations can be even more concise.

Synopsis

Documentation

type Constraints t c = Constraints' (Rep t) c Source #

Constraints is a constraint type synonym, containing the constraint requirements for an instance for t of class c. It requires an instance of class c for each component of t.

Useful for the writing the context of StandaloneDeriving clauses:

deriving instance Constraints MyType Eq => Eq MyType

Template Haskell helpers

makeDeriving :: Name -> Name -> DecsQ Source #

TemplateHaskell generation of a standalone deriving declaration.

makeDeriving ''Ord ''MyType

Generates:

deriving instance Constraints MyType Ord => Ord MyType

makeDerivings :: [Name] -> [Name] -> DecsQ Source #

TemplateHaskell generation of multiple standalone deriving declarations.

makeDerivings [''Eq, ''Ord, ''Show] [''MyType, ''MyOtherType]

Generates the deriving declarations for all given classes and types.

makeInstance :: Name -> Name -> DecsQ Source #

TemplateHaskell generation of an instance declaration with no methods.

makeDeriving ''Binary ''MyType

Generates:

instance Constraints MyType Binary => Binary MyType

makeInstances :: [Name] -> [Name] -> DecsQ Source #

TemplateHaskell generation of multiple instance declarations.

makeInstances [''Binary, ''NFData] [''MyType, ''MyOtherType]

Generates the instances declarations for all given classes and types.