How to create a new Data.Derive instance generator?

108 views Asked by At

Does anyone know of a step-by-step tutorial of how to create a Data.Derive instance generator? There seems to be an amount of documentation for how to use an existing deriving instance generators.

For those not familiar with Data.Derive (or if I'm just particularly unclear), this is what I want to do. Given a trivial newtype example like,

newtype WrapperT  α = WrapperT (StateT Integer  α)
    deriving (Applicative, Functor, Monad)

instance HzMonadBase  => HzMonadBase (WrapperT ) where
    data ExprTyp (WrapperT ) α = WrapperTE (ExprTyp (StateT Integer ) α)

I want to generate all of these instances (and Constraints data family). They are pretty much parameterized by the strings "WrapperT", "WrapperTE", and "StateT Integer α".

data instance Constraints (ExprTyp (WrapperT )) α =
    (Suitable (ExprTyp ) α) => WrapperT_Constr
instance (Suitable (ExprTyp ) α) => Suitable (ExprTyp (WrapperT )) α where
    constraints = WrapperT_Constr

instance HzMonadBase  => HzExprTrans (ExprTyp (WrapperT )) where
    type PrimExpr (ExprTyp (WrapperT )) = ExprTyp (StateT Integer )
    e_lift = fmap WrapperTE
    e_lower = fmap (\(WrapperTE x) -> x)
    e_lower_suitably x@(ExprT v) f =
        withConstraintsOf v $ \WrapperT_Constr -> f (e_lower x)

instance HzMonadBase  => BinaryCmpExpr (ExprTyp (WrapperT ))
instance HzMonadBase  => BinaryOpExpr (ExprTyp (WrapperT ))
instance HzMonadBase  => SketchConstrExpr (ExprTyp (WrapperT ))
instance HzMonadBase  => Arithmetic (ExprTyp (WrapperT ))
instance HzMonadBase  => VariablesExpr (ExprTyp (WrapperT ))

instance HzMonadBase  => HzMonadTrans (WrapperT ) where
    type BaseMonad (WrapperT ) = StateT Integer 
    lift = WrapperT
instance HzMonadBase  => HzMonadUnliftTrans (WrapperT ) where
    unlift (WrapperT x) = x
0

There are 0 answers