Copyright | (c) Sirui Lu 2024 |
---|---|
License | BSD-3-Clause (see the LICENSE file) |
Maintainer | siruilu@cs.washington.edu |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- class DeriveTypeParamHandler handler where
- handleTypeParams :: Int -> handler -> [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] -> Q [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])]
- handleBody :: handler -> [[Type]] -> Q [Pred]
- data NatShouldBePositive = NatShouldBePositive
- data IsFPBits = IsFPBits {}
- data PrimaryConstraint = PrimaryConstraint {}
- data SomeDeriveTypeParamHandler where
- SomeDeriveTypeParamHandler :: DeriveTypeParamHandler handler => handler -> SomeDeriveTypeParamHandler
Documentation
class DeriveTypeParamHandler handler where Source #
A derive type param handler handles type parameters and provides constraints or instantiations for them.
The first argument is the number of types that are zipped together. For
most classes, this is 1, but for some classes, like ToCon
, this is
2.
The second argument is the handler itself.
The third argument is a list of type parameters and their constraints. Each
entry in the list corresponds to a type parameter of the datatype. The
first element in the pair is a list of zipped type parameters with possibly
concrete types. For example, if we are deriving ToCon
for
Either
, the argument will be:
[([(e0, Nothing), (e1, Nothing)], Nothing), ([(a0, Nothing), (a1, Nothing)], Nothing)]
We can see that the type parameters for the concrete and symbolic Either
types are zipped together: the first element of the list are for the error
types, and the second element of the list are for the value types.
The handler may concretize some types, or add constraints based on the type parameters.
handleTypeParams :: Int -> handler -> [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] -> Q [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] Source #
Instances
data NatShouldBePositive Source #
Ensures that type parameters with the kind Nat
are known and positive.
Instances
DeriveTypeParamHandler NatShouldBePositive Source # | |
Defined in Grisette.Internal.TH.DeriveTypeParamHandler handleTypeParams :: Int -> NatShouldBePositive -> [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] -> Q [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] Source # handleBody :: NatShouldBePositive -> [[Type]] -> Q [Pred] Source # |
Ensures that the type parameters are valid for floating point operations.
Instances
data PrimaryConstraint Source #
Adds a primary constraint to the type parameters. It applies the class to each type parameter that are zipped into a list, with the desired kinds.
For example, if we are deriving ToCon
for Either
, and the input
to this handler is as follows:
[([(e0, Nothing), (e1, Nothing)], Nothing), ([(a0, Nothing), (a1, Nothing)], Nothing)]
Then this will generate constraints for the type parameters of Either
:
[([(e0, Nothing), (e1, Nothing)], Just [ToCon e0 e1]), ([(a0, Nothing), (a1, Nothing)], Just [ToCon a0 a1])]
Type parameters that are already handled by other handlers can be ignored.
Instances
DeriveTypeParamHandler PrimaryConstraint Source # | |
Defined in Grisette.Internal.TH.DeriveTypeParamHandler handleTypeParams :: Int -> PrimaryConstraint -> [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] -> Q [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] Source # handleBody :: PrimaryConstraint -> [[Type]] -> Q [Pred] Source # |
data SomeDeriveTypeParamHandler where Source #
A type that can handle type parameters.
SomeDeriveTypeParamHandler :: DeriveTypeParamHandler handler => handler -> SomeDeriveTypeParamHandler |
Instances
DeriveTypeParamHandler SomeDeriveTypeParamHandler Source # | |
Defined in Grisette.Internal.TH.DeriveTypeParamHandler handleTypeParams :: Int -> SomeDeriveTypeParamHandler -> [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] -> Q [([(TyVarBndrUnit, Maybe Type)], Maybe [Pred])] Source # handleBody :: SomeDeriveTypeParamHandler -> [[Type]] -> Q [Pred] Source # |