fitspec-0.4.5: refining property sets for testing Haskell programs

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

Test.FitSpec.Derive

Description

Experimental module for deriving Mutable and ShowMutable instances

Needs GHC and Template Haskell (tested on GHC 7.4, 7.6, 7.8, 7.10 and 8.0)

Despite Mutable instances being actually very simple to write manually, this module can be used to derive those instances automatically. However, it will not work on all cases: when that happens, you should write your instances manually.

If FitSpec does not compile under later GHCs, this module is probably the culprit.

Synopsis

Documentation

deriveMutable :: Name -> DecsQ Source #

Derives Mutable, ShowMutable and (optionally) Listable instances for a given type Name.

Consider the following Stack datatype:

data Stack a = Stack a (Stack a) | Empty

Writing

deriveMutable ''Stack

will automatically derive the following Listable, Mutable and ShowMutable instances:

instance Listable a => Listable (Stack a) where
  tiers = cons2 Stack \/ cons0 Empty

instance (Eq a, Listable a) => Mutable a
  where mutiers = mutiersEq

instance (Eq a, Show a) => ShowMutable a
  where mutantS = mutantSEq

If a Listable instance already exists, it is not derived. (cf.: deriveListable)

Needs the TemplateHaskell extension.

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

Derives a Mutable instance for a given type Name using a given context for all type variables.