Copyright | (c) 2015-2024 Rudy Matela |
---|---|
License | 3-Clause BSD (see the file LICENSE) |
Maintainer | Rudy Matela <rudy@matela.com.br> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module is part of LeanCheck, a simple enumerative property-based testing library.
Needs GHC and Template Haskell (tested on GHC 7.4, 7.6, 7.8, 7.10, 8.0, 8.2, 8.4, 8.6 and 8.8).
If LeanCheck does not compile under later GHCs, this module is probably the culprit.
If you rather do this through GHC Generics, please see: Test.LeanCheck.Generic (experimental).
Synopsis
- deriveListable :: Name -> DecsQ
- deriveListableIfNeeded :: Name -> DecsQ
- deriveListableCascading :: Name -> DecsQ
- deriveTiers :: Name -> ExpQ
- deriveList :: Name -> ExpQ
Documentation
deriveListable :: Name -> DecsQ Source #
Derives a Listable
instance for a given type Name
.
Consider the following Stack
datatype:
data Stack a = Stack a (Stack a) | Empty
Writing
deriveListable ''Stack
will automatically derive the following Listable
instance:
instance Listable a => Listable (Stack a) where tiers = cons2 Stack \/ cons0 Empty
Warning: if the values in your type need to follow a data invariant, the derived instance won't respect it. Use this only on "free" datatypes.
Needs the TemplateHaskell
extension.
deriveListableIfNeeded :: Name -> DecsQ Source #
Same as deriveListable
but does not warn when the requested instance
already exists. The function deriveListable
is preferable in most
situations.
deriveListableCascading :: Name -> DecsQ Source #
Derives a Listable
instance for a given type Name
cascading derivation of type arguments as well.
Consider the following series of datatypes:
data Position = CEO | Manager | Programmer data Person = Person { name :: String , age :: Int , position :: Position } data Company = Company { name :: String , employees :: [Person] }
Writing
deriveListableCascading ''Company
will automatically derive the following three Listable
instances:
instance Listable Position where tiers = cons0 CEO \/ cons0 Manager \/ cons0 Programmer instance Listable Person where tiers = cons3 Person instance Listable Company where tiers = cons2 Company
deriveTiers :: Name -> ExpQ Source #