Copyright | (c) 2017 Rudy Matela |
---|---|
License | 3-Clause BSD (see the file LICENSE) |
Maintainer | Rudy Matela <rudy@matela.com.br> |
Safe Haskell | None |
Language | Haskell2010 |
This module is part of Extrapolate, a library for generalization of counter-examples.
This is a module for deriving Generalizable
instances.
Needs GHC and Template Haskell (tested on GHC 8.0).
If Extrapolate does not compile under later GHCs, this module is the probable culprit.
Documentation
deriveGeneralizable :: Name -> DecsQ Source #
Derives a Generalizable
instance for a given type Name
.
Consider the following Stack
datatype:
data Stack a = Stack a (Stack a) | Empty
Writing
deriveGeneralizable ''Stack
will automatically derive the following Generalizable
instance:
instance Generalizable a => Generalizable (Stack a) where expr s@(Stack x y) = constant "Stack" (Stack ->>: s) :$ expr x :$ expr y expr s@Empty = constant "Empty" (Empty -: s) instances s = this "s" s $ let Stack x y = Stack undefined undefined `asTypeOf` s in instances x . instances y
This function needs the TemplateHaskell
extension.
deriveGeneralizableIfNeeded :: Name -> DecsQ Source #
Same as deriveGeneralizable
but does not warn when instance already exists
(deriveGeneralizable
is preferable).
deriveGeneralizableCascading :: Name -> DecsQ Source #
Derives a Generalizable
instance for a given type Name
cascading derivation of type arguments as well.