extrapolate-0.2.4: generalize counter-examples of test properties

Copyright(c) 2017 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellNone
LanguageHaskell2010

Test.Extrapolate.Derive

Description

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.

Synopsis

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.