Safe Haskell | None |
---|---|
Language | Haskell2010 |
Speculate: discovery of properties by reasoning from test results
Speculate automatically discovers laws about Haskell functions. Those laws involve:
- equations, such as
id x == x
; - inequalities, such as
0 <= x * x
; - conditional equations, such as
x <= 0 ==> x + abs x == 0
.
_Example:_ the following program prints laws about 0
, 1
, +
and abs
.
import Test.Speculate main :: IO () main = speculate args { constants = [ showConstant (0::Int) , showConstant (1::Int) , constant "+" ((+) :: Int -> Int -> Int) , constant "abs" (abs :: Int -> Int) , background , constant "<=" ((<=) :: Int -> Int -> Bool) ] }
- speculate :: Args -> IO ()
- data Args = Args {
- maxSize :: Int
- maxTests :: Int
- constants :: [Expr]
- instances :: [Instances]
- maxSemiSize :: Int
- maxCondSize :: Int
- maxVars :: Int
- showConstants :: Bool
- showEquations :: Bool
- showSemiequations :: Bool
- showConditions :: Bool
- showConstantLaws :: Bool
- minTests :: Int -> Int
- maxConstants :: Maybe Int
- maxDepth :: Maybe Int
- showTheory :: Bool
- showArgs :: Bool
- showHelp :: Bool
- evalTimeout :: Maybe Double
- force :: Bool
- extra :: [String]
- exclude :: [String]
- onlyTypes :: [String]
- showClassesFor :: [Int]
- showDot :: Bool
- quietDot :: Bool
- args :: Args
- data Expr
- constant :: Typeable a => String -> a -> Expr
- showConstant :: (Typeable a, Show a) => a -> Expr
- hole :: (Listable a, Typeable a) => a -> Expr
- foreground :: Expr
- background :: Expr
- type Instances = [Instance]
- ins :: (Typeable a, Listable a, Show a, Eq a, Ord a) => String -> a -> Instances
- eq :: (Typeable a, Eq a) => a -> Instances
- ord :: (Typeable a, Ord a) => a -> Instances
- eqWith :: (Typeable a, Eq a) => (a -> a -> Bool) -> Instances
- ordWith :: (Typeable a, Ord a) => (a -> a -> Bool) -> Instances
- names :: Instances -> TypeRep -> [String]
- report :: Args -> IO ()
- getArgs :: Args -> IO Args
- module Test.LeanCheck
- module Test.LeanCheck.Utils
- module Data.Typeable
Documentation
speculate :: Args -> IO () Source #
Calls Speculate. See the example above (at the top of the file).
Its only argument is an Args
structure.
Arguments to Speculate
Args | |
|
The constants list
An encoded Haskell functional-application expression for use by Speculate.
constant :: Typeable a => String -> a -> Expr Source #
Encode a constant Haskell expression for use by Speculate.
It takes a string representation of a value and a value, returning an
Expr
. Examples:
constant "0" 0 constant "'a'" 'a' constant "True" True constant "id" (id :: Int -> Int) constant "(+)" ((+) :: Int -> Int -> Int) constant "sort" (sort :: [Bool] -> [Bool])
hole :: (Listable a, Typeable a) => a -> Expr Source #
(intended for advanced users)
hole (undefined :: Ty)
returns a hole of type Ty
By convention, a Hole is a variable named with the empty string.
foreground :: Expr Source #
A special Expr
value.
When provided on the constants
list,
makes all the following constants foreground
constants.
background :: Expr Source #
A special Expr
value.
When provided on the constants
list,
makes all the following constants background
constants.
Background constants can appear in laws about other constants, but not by
themselves.
The instances list
Misc.
module Test.LeanCheck
module Test.LeanCheck.Utils
module Data.Typeable