code-conjure-0.5.14: synthesize Haskell functions out of partial definitions

Conjure

Description

A library for Conjuring function implementations from tests or partial definitions. (a.k.a.: functional inductive programming)

This is currently an experimental tool in its early stages, don't expect much from its current version. It is just a piece of curiosity in its current state.

Step 1: declare your partial function

square :: Int -> Int
square 0  =  0
square 1  =  1
square 2  =  4

Step 2: declare a list with the potential building blocks:

primitives :: [Prim]
primitives =
[ pr (0::Int)
, pr (1::Int)
, prim "+" ((+) :: Int -> Int -> Int)
, prim "*" ((*) :: Int -> Int -> Int)
]

Step 3: call conjure and see your generated function:

> conjure "square" square primitives
square :: Int -> Int
-- testing 3 combinations of argument values
-- pruning with 14/25 rules
-- looking through 3 candidates of size 1
-- looking through 4 candidates of size 2
-- looking through 9 candidates of size 3
square x  =  x * x
Synopsis

Basic use

conjure :: Conjurable f => String -> f -> [Prim] -> IO () Source #

Conjures an implementation of a partially defined function.

Takes a String with the name of a function, a partially-defined function from a conjurable type, and a list of building blocks encoded as Exprs.

For example, given:

square :: Int -> Int
square 0  =  0
square 1  =  1
square 2  =  4

primitives :: [Prim]
primitives =
[ pr (0::Int)
, pr (1::Int)
, prim "+" ((+) :: Int -> Int -> Int)
, prim "*" ((*) :: Int -> Int -> Int)
]

The conjure function does the following:

> conjure "square" square primitives
square :: Int -> Int
-- pruning with 14/25 rules
-- testing 3 combinations of argument values
-- looking through 3 candidates of size 1
-- looking through 3 candidates of size 2
-- looking through 5 candidates of size 3
square x  =  x * x

The primitives list is defined with pr and prim.

type Prim = (Expr, Reification) Source #

A primtive expression (paired with instance reification).

pr :: (Conjurable a, Show a) => a -> Prim Source #

Provides a primitive value to Conjure. To be used on Show instances. (cf. prim)

prim :: Conjurable a => String -> a -> Prim Source #

Provides a primitive value to Conjure. To be used on values that are not Show instances such as functions. (cf. pr)

prif :: Conjurable a => a -> Prim Source #

Provides an if condition bound to the given return type.

primOrdCaseFor :: Conjurable a => a -> Prim Source #

Provides a case condition bound to the given return type.

conjureWithMaxSize :: Conjurable f => Int -> String -> f -> [Prim] -> IO () Source #

Like conjure but allows setting the maximum size of considered expressions instead of the default value of 12.

conjureWithMaxSize 10 "function" function [...]

conjureWith :: Conjurable f => Args -> String -> f -> [Prim] -> IO () Source #

Like conjure but allows setting options through Args/args.

conjureWith args{maxSize = 11} "function" function [...]

data Args Source #

Arguments to be passed to conjureWith or conjpureWith. See args for the defaults.

Constructors

 Args FieldsmaxTests :: Intmaximum number of tests to each candidatemaxSize :: Intmaximum size of candidate bodiesmaxEvalRecursions :: Intmaximum number of recursive evaluations when testing candidatesmaxEquationSize :: Intmaximum size of equation operandsmaxSearchTests :: Intmaximum number of tests to search for defined valuesmaxDeconstructionSize :: Intmaximum size of deconstructions (e.g.: _ - 1)carryOn :: Boolwhether to carry on after finding a suitable candidateshowTheory :: Boolshow theory discovered by Speculate used in pruningusePatterns :: Booluse pattern matching to create (recursive) candidatesrewriting :: Boolunique-modulo-rewriting candidatesrequireDescent :: Boolrequire recursive calls to deconstruct argumentsadHocRedundancy :: Boolad-hoc redundancy checkscopyBindings :: Boolcopy partial definition bindings in candidatesatomicNumbers :: Boolrestrict constant/ground numeric expressions to atomsuniqueCandidates :: Boolunique-modulo-testing candidates

Default arguments to conjure.

• 60 tests
• functions of up to 12 symbols
• maximum of one recursive call allowed in candidate bodies
• maximum evaluation of up to 60 recursions
• pruning with equations up to size 5
• search for defined applications for up to 100000 combinations
• require recursive calls to deconstruct arguments
• don't show the theory used in pruning
• do not make candidates unique module testing

data Expr #

Values of type Expr represent objects or applications between objects. Each object is encapsulated together with its type and string representation. Values encoded in Exprs are always monomorphic.

An Expr can be constructed using:

• val, for values that are Show instances;
• value, for values that are not Show instances, like functions;
• :$, for applications between Exprs. > val False False :: Bool > value "not" not :$ val False
not False :: Bool

An Expr can be evaluated using evaluate, eval or evl.

> evl $val (1 :: Int) :: Int 1 > evaluate$ val (1 :: Int) :: Maybe Bool
Nothing
> eval 'a' (val 'b')
'b'

Showing a value of type Expr will return a pretty-printed representation of the expression together with its type.

> show (value "not" not :$val False) "not False :: Bool" Expr is like Dynamic but has support for applications and variables (:$, var).

The var underscore convention: Functions that manipulate Exprs usually follow the convention where a value whose String representation starts with '_' represents a variable.

Instances

Instances details
 Shows Exprs with their types.> show (value "not" not :$val False) "not False :: Bool" Instance detailsDefined in Data.Express.Core MethodsshowsPrec :: Int -> Expr -> ShowS #show :: Expr -> String #showList :: [Expr] -> ShowS # O(n). Does not evaluate values when comparing, but rather uses their representation as strings and their types.This instance works for ill-typed expressions. Instance detailsDefined in Data.Express.Core Methods(==) :: Expr -> Expr -> Bool #(/=) :: Expr -> Expr -> Bool # O(n). Does not evaluate values when comparing, but rather uses their representation as strings and their types.This instance works for ill-typed expressions.Expressions come first when they have smaller complexity (compareComplexity) or when they come first lexicographically (compareLexicographically). Instance detailsDefined in Data.Express.Core Methodscompare :: Expr -> Expr -> Ordering #(<) :: Expr -> Expr -> Bool #(<=) :: Expr -> Expr -> Bool #(>) :: Expr -> Expr -> Bool #(>=) :: Expr -> Expr -> Bool #max :: Expr -> Expr -> Expr #min :: Expr -> Expr -> Expr # val :: (Typeable a, Show a) => a -> Expr # O(1). A shorthand for value for values that are Show instances. > val (0 :: Int) 0 :: Int > val 'a' 'a' :: Char > val True True :: Bool Example equivalences to value: val 0 = value "0" 0 val 'a' = value "'a'" 'a' val True = value "True" True value :: Typeable a => String -> a -> Expr # O(1). It takes a string representation of a value and a value, returning an Expr with that terminal value. For instances of Show, it is preferable to use val. > value "0" (0 :: Integer) 0 :: Integer > value "'a'" 'a' 'a' :: Char > value "True" True True :: Bool > value "id" (id :: Int -> Int) id :: Int -> Int > value "(+)" ((+) :: Int -> Int -> Int) (+) :: Int -> Int -> Int > value "sort" (sort :: [Bool] -> [Bool]) sort :: [Bool] -> [Bool] Conjuring from a specification conjureFromSpec :: Conjurable f => String -> (f -> Bool) -> [Prim] -> IO () Source # Conjures an implementation from a function specification. This function works like conjure but instead of receiving a partial definition it receives a boolean filter / property about the function. For example, given: squareSpec :: (Int -> Int) -> Bool squareSpec square = square 0 == 0 && square 1 == 1 && square 2 == 4 Then: > conjureFromSpec "square" squareSpec primitives square :: Int -> Int -- pruning with 14/25 rules -- looking through 3 candidates of size 1 -- looking through 4 candidates of size 2 -- looking through 9 candidates of size 3 square x = x * x This allows users to specify QuickCheck-style properties, here is an example using LeanCheck: import Test.LeanCheck (holds, exists) squarePropertySpec :: (Int -> Int) -> Bool squarePropertySpec square = and [ holds n$ \x -> square x >= x
, holds n $\x -> square x >= 0 , exists n$ \x -> square x > x
]  where  n = 60

conjureFromSpecWith :: Conjurable f => Args -> String -> (f -> Bool) -> [Prim] -> IO () Source #

Like conjureFromSpec but allows setting options through Args/args.

conjureFromSpecWith args{maxSize = 11} "function" spec [...]

When using custom types

class (Typeable a, Name a) => Conjurable a where Source #

Class of Conjurable types. Functions are Conjurable if all their arguments are Conjurable, Listable and Showable.

For atomic types that are Listable, instances are defined as:

instance Conjurable Atomic where
conjureTiers  =  reifyTiers

For atomic types that are both Listable and Eq, instances are defined as:

instance Conjurable Atomic where
conjureTiers     =  reifyTiers
conjureEquality  =  reifyEquality

For types with subtypes, instances are defined as:

instance Conjurable Composite where
conjureTiers     =  reifyTiers
conjureEquality  =  reifyEquality
conjureSubTypes x  =  conjureType y
.  conjureType z
.  conjureType w
where
(Composite ... y ... z ... w ...)  =  x

Above x, y, z and w are just proxies. The Proxy type was avoided for backwards compatibility.

Please see the source code of Conjure.Conjurable for more examples.

(cf. reifyTiers, reifyEquality, conjureType)

Minimal complete definition

conjureExpress

Methods

Returns Just the == function encoded as an Expr when available or Nothing otherwise.

Use reifyEquality when defining this.

conjureTiers :: a -> Maybe [[Expr]] Source #

Returns Just tiers of values encoded as Exprs when possible or Nothing otherwise.

Use reifyTiers when defining this.

conjureCases :: a -> [Expr] Source #

Returns a top-level case breakdown.

conjureSize :: a -> Int Source #

Returns the (recursive) size of the given value.

conjureExpress :: a -> Expr -> Expr Source #

Returns a function that deeply reencodes an expression when possible. (id when not available.)

Use reifyExpress when defining this.

Instances

Instances details
 Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureCases :: Int16 -> [Expr] Source #conjureArgumentCases :: Int16 -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Int16 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureCases :: Int32 -> [Expr] Source #conjureArgumentCases :: Int32 -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Int32 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureCases :: Int64 -> [Expr] Source #conjureArgumentCases :: Int64 -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Int64 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Int8 -> Maybe [[Expr]] Source #conjureCases :: Int8 -> [Expr] Source #conjureArgumentCases :: Int8 -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Int8 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Word16 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Word32 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Word64 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureCases :: Word8 -> [Expr] Source #conjureArgumentCases :: Word8 -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Word8 Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Ordering Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: A -> Maybe [[Expr]] Source #conjureCases :: A -> [Expr] Source #conjureArgumentCases :: A -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe A Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: B -> Maybe [[Expr]] Source #conjureCases :: B -> [Expr] Source #conjureArgumentCases :: B -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe B Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: C -> Maybe [[Expr]] Source #conjureCases :: C -> [Expr] Source #conjureArgumentCases :: C -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe C Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: D -> Maybe [[Expr]] Source #conjureCases :: D -> [Expr] Source #conjureArgumentCases :: D -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe D Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: E -> Maybe [[Expr]] Source #conjureCases :: E -> [Expr] Source #conjureArgumentCases :: E -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe E Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: F -> Maybe [[Expr]] Source #conjureCases :: F -> [Expr] Source #conjureArgumentCases :: F -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe F Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Integer Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: () -> [Expr] Source #conjureEquality :: () -> Maybe Expr Source #conjureTiers :: () -> Maybe [[Expr]] Source #conjureIf :: () -> Expr Source #conjureCases :: () -> [Expr] Source #conjureArgumentCases :: () -> [[Expr]] Source #conjureSize :: () -> Int Source #conjureExpress :: () -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe () Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Bool -> Maybe [[Expr]] Source #conjureCases :: Bool -> [Expr] Source #conjureArgumentCases :: Bool -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Bool Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Char -> Maybe [[Expr]] Source #conjureCases :: Char -> [Expr] Source #conjureArgumentCases :: Char -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Char Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Double Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureCases :: Float -> [Expr] Source #conjureArgumentCases :: Float -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Float Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Int -> Maybe [[Expr]] Source #conjureCases :: Int -> [Expr] Source #conjureArgumentCases :: Int -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Int Source # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Word -> Maybe [[Expr]] Source #conjureCases :: Word -> [Expr] Source #conjureArgumentCases :: Word -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe Word Source # (RealFloat a, Conjurable a, Listable a, Show a, Eq a, Express a) => Conjurable (Complex a) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: Complex a -> Maybe [[Expr]] Source #conjureCases :: Complex a -> [Expr] Source #conjureArgumentCases :: Complex a -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (Complex a) Source # (Integral a, Conjurable a, Listable a, Show a, Eq a, Express a) => Conjurable (Ratio a) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: Ratio a -> [Expr] Source #conjureTiers :: Ratio a -> Maybe [[Expr]] Source #conjureCases :: Ratio a -> [Expr] Source #conjureArgumentCases :: Ratio a -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (Ratio a) Source # (Conjurable a, Listable a, Show a, Express a) => Conjurable (Maybe a) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: Maybe a -> [Expr] Source #conjureTiers :: Maybe a -> Maybe [[Expr]] Source #conjureCases :: Maybe a -> [Expr] Source #conjureArgumentCases :: Maybe a -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (Maybe a) Source # (Conjurable a, Listable a, Express a, Show a) => Conjurable [a] Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: [a] -> [Expr] Source #conjureEquality :: [a] -> Maybe Expr Source #conjureTiers :: [a] -> Maybe [[Expr]] Source #conjureSubTypes :: [a] -> Reification Source #conjureIf :: [a] -> Expr Source #conjureCases :: [a] -> [Expr] Source #conjureArgumentCases :: [a] -> [[Expr]] Source #conjureSize :: [a] -> Int Source #conjureExpress :: [a] -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe [a] Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b) => Conjurable (Either a b) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: Either a b -> [Expr] Source #conjureTiers :: Either a b -> Maybe [[Expr]] Source #conjureIf :: Either a b -> Expr Source #conjureCases :: Either a b -> [Expr] Source #conjureArgumentCases :: Either a b -> [[Expr]] Source #conjureSize :: Either a b -> Int Source #conjureExpress :: Either a b -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (Either a b) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b) => Conjurable (a, b) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b) -> [Expr] Source #conjureEquality :: (a, b) -> Maybe Expr Source #conjureTiers :: (a, b) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b) -> Reification Source #conjureIf :: (a, b) -> Expr Source #conjureCases :: (a, b) -> [Expr] Source #conjureArgumentCases :: (a, b) -> [[Expr]] Source #conjureSize :: (a, b) -> Int Source #conjureExpress :: (a, b) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b) Source # (Conjurable a, Conjurable b) => Conjurable (a -> b) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a -> b) -> [Expr] Source #conjureEquality :: (a -> b) -> Maybe Expr Source #conjureTiers :: (a -> b) -> Maybe [[Expr]] Source #conjureSubTypes :: (a -> b) -> Reification Source #conjureIf :: (a -> b) -> Expr Source #conjureCases :: (a -> b) -> [Expr] Source #conjureArgumentCases :: (a -> b) -> [[Expr]] Source #conjureSize :: (a -> b) -> Int Source #conjureExpress :: (a -> b) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a -> b) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c) => Conjurable (a, b, c) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c) -> [Expr] Source #conjureEquality :: (a, b, c) -> Maybe Expr Source #conjureTiers :: (a, b, c) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c) -> Reification Source #conjureIf :: (a, b, c) -> Expr Source #conjureCases :: (a, b, c) -> [Expr] Source #conjureArgumentCases :: (a, b, c) -> [[Expr]] Source #conjureSize :: (a, b, c) -> Int Source #conjureExpress :: (a, b, c) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d) => Conjurable (a, b, c, d) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d) -> [Expr] Source #conjureEquality :: (a, b, c, d) -> Maybe Expr Source #conjureTiers :: (a, b, c, d) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d) -> Reification Source #conjureIf :: (a, b, c, d) -> Expr Source #conjureCases :: (a, b, c, d) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d) -> [[Expr]] Source #conjureSize :: (a, b, c, d) -> Int Source #conjureExpress :: (a, b, c, d) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e) => Conjurable (a, b, c, d, e) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e) -> [Expr] Source #conjureEquality :: (a, b, c, d, e) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e) -> Reification Source #conjureIf :: (a, b, c, d, e) -> Expr Source #conjureCases :: (a, b, c, d, e) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e) -> Int Source #conjureExpress :: (a, b, c, d, e) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f) => Conjurable (a, b, c, d, e, f) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f) -> Reification Source #conjureIf :: (a, b, c, d, e, f) -> Expr Source #conjureCases :: (a, b, c, d, e, f) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f) -> Int Source #conjureExpress :: (a, b, c, d, e, f) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g) => Conjurable (a, b, c, d, e, f, g) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g, Conjurable h, Listable h, Show h, Express h) => Conjurable (a, b, c, d, e, f, g, h) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g, h) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g, h) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g, h) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g, h) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g, h) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g, h) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g, h) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g, h) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g, h) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g, h) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g, Conjurable h, Listable h, Show h, Express h, Conjurable i, Listable i, Show i, Express i) => Conjurable (a, b, c, d, e, f, g, h, i) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g, h, i) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g, h, i) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g, h, i) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g, h, i) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g, h, i) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g, h, i) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g, h, i) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g, h, i) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g, h, i) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g, h, i) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g, Conjurable h, Listable h, Show h, Express h, Conjurable i, Listable i, Show i, Express i, Conjurable j, Listable j, Show j, Express j) => Conjurable (a, b, c, d, e, f, g, h, i, j) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g, h, i, j) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g, h, i, j) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g, h, i, j) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g, h, i, j) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g, h, i, j) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g, h, i, j) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g, h, i, j) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g, h, i, j) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g, h, i, j) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g, h, i, j) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g, Conjurable h, Listable h, Show h, Express h, Conjurable i, Listable i, Show i, Express i, Conjurable j, Listable j, Show j, Express j, Conjurable k, Listable k, Show k, Express k) => Conjurable (a, b, c, d, e, f, g, h, i, j, k) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g, h, i, j, k) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g, h, i, j, k) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g, h, i, j, k) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g, h, i, j, k) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g, h, i, j, k) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g, h, i, j, k) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g, h, i, j, k) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g, h, i, j, k) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g, h, i, j, k) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g, h, i, j, k) Source # (Conjurable a, Listable a, Show a, Express a, Conjurable b, Listable b, Show b, Express b, Conjurable c, Listable c, Show c, Express c, Conjurable d, Listable d, Show d, Express d, Conjurable e, Listable e, Show e, Express e, Conjurable f, Listable f, Show f, Express f, Conjurable g, Listable g, Show g, Express g, Conjurable h, Listable h, Show h, Express h, Conjurable i, Listable i, Show i, Express i, Conjurable j, Listable j, Show j, Express j, Conjurable k, Listable k, Show k, Express k, Conjurable l, Listable l, Show l, Express l) => Conjurable (a, b, c, d, e, f, g, h, i, j, k, l) Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureArgumentHoles :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [Expr] Source #conjureEquality :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Maybe Expr Source #conjureTiers :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Maybe [[Expr]] Source #conjureSubTypes :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Reification Source #conjureIf :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Expr Source #conjureCases :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [Expr] Source #conjureArgumentCases :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [[Expr]] Source #conjureSize :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Int Source #conjureExpress :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Expr -> Expr Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe (a, b, c, d, e, f, g, h, i, j, k, l) Source #

reifyExpress :: (Express a, Show a) => a -> Expr -> Expr Source #

Reifies the expr function in a Conjurable type instance.

This is to be used in the definition of conjureExpress of Conjurable typeclass instances.

instance ... => Conjurable <Type> where
...
conjureExpress  =  reifyExpress
...

reifyEquality :: (Eq a, Typeable a) => a -> Maybe Expr Source #

Reifies equality == in a Conjurable type instance.

This is to be used in the definition of conjureEquality of Conjurable typeclass instances:

instance ... => Conjurable <Type> where
...
conjureEquality  =  reifyEquality
...

reifyTiers :: (Listable a, Show a, Typeable a) => a -> Maybe [[Expr]] Source #

Reifies equality to be used in a conjurable type.

This is to be used in the definition of conjureTiers of Conjurable typeclass instances:

instance ... => Conjurable <Type> where
...
conjureTiers  =  reifyTiers
...

conjureType :: Conjurable a => a -> Reification Source #

To be used in the implementation of conjureSubTypes.

instance ... => Conjurable <Type> where
...
conjureSubTypes x  =  conjureType (field1 x)
.  conjureType (field2 x)
.  ...
.  conjureType (fieldN x)
...

class Name a where #

If we were to come up with a variable name for the given type what name would it be?

An instance for a given type  Ty  is simply given by:

instance Name Ty where name _ = "x"

Examples:

> name (undefined :: Int)
"x"
> name (undefined :: Bool)
"p"
> name (undefined :: [Int])
"xs"

This is then used to generate an infinite list of variable names:

> names (undefined :: Int)
["x", "y", "z", "x'", "y'", "z'", "x''", "y''", "z''", ...]
> names (undefined :: Bool)
["p", "q", "r", "p'", "q'", "r'", "p''", "q''", "r''", ...]
> names (undefined :: [Int])
["xs", "ys", "zs", "xs'", "ys'", "zs'", "xs''", "ys''", ...]

Minimal complete definition

Nothing

Methods

name :: a -> String #

O(1).

Returns a name for a variable of the given argument's type.

> name (undefined :: Int)
"x"
> name (undefined :: [Bool])
"ps"
> name (undefined :: [Maybe Integer])
"mxs"

The default definition is:

name _ = "x"

Instances

Instances details
 Instance detailsDefined in Data.Express.Name Methodsname :: Int16 -> String # Instance detailsDefined in Data.Express.Name Methodsname :: Int32 -> String # Instance detailsDefined in Data.Express.Name Methodsname :: Int64 -> String # Instance detailsDefined in Data.Express.Name Methodsname :: Int8 -> String # Instance detailsDefined in Data.Express.Name Methods Instance detailsDefined in Data.Express.Name Methods Instance detailsDefined in Data.Express.Name Methods Instance detailsDefined in Data.Express.Name Methods Instance detailsDefined in Data.Express.Name Methodsname :: Word8 -> String # name (undefined :: Ordering) = "o" names (undefined :: Ordering) = ["o", "p", "q", "o'", ...] Instance detailsDefined in Data.Express.Name Methods Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: A -> String # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: B -> String # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: C -> String # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: D -> String # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: E -> String # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: F -> String # name (undefined :: Integer) = "x" names (undefined :: Integer) = ["x", "y", "z", "x'", ...] Instance detailsDefined in Data.Express.Name Methods Name () name (undefined :: ()) = "u" names (undefined :: ()) = ["u", "v", "w", "u'", "v'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: () -> String # name (undefined :: Bool) = "p" names (undefined :: Bool) = ["p", "q", "r", "p'", "q'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Bool -> String # name (undefined :: Char) = "c" names (undefined :: Char) = ["c", "d", "e", "c'", "d'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Char -> String # name (undefined :: Double) = "x" names (undefined :: Double) = ["x", "y", "z", "x'", ...] Instance detailsDefined in Data.Express.Name Methods name (undefined :: Float) = "x" names (undefined :: Float) = ["x", "y", "z", "x'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Float -> String # name (undefined :: Int) = "x" names (undefined :: Int) = ["x", "y", "z", "x'", "y'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Int -> String # Instance detailsDefined in Data.Express.Name Methodsname :: Word -> String # Name (Complex a) name (undefined :: Complex) = "x" names (undefined :: Complex) = ["x", "y", "z", "x'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Complex a -> String # Name (Ratio a) name (undefined :: Rational) = "q" names (undefined :: Rational) = ["q", "r", "s", "q'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Ratio a -> String # Name a => Name (Maybe a) names (undefined :: Maybe Int) = ["mx", "mx1", "mx2", ...] nemes (undefined :: Maybe Bool) = ["mp", "mp1", "mp2", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Maybe a -> String # Name a => Name [a] names (undefined :: [Int]) = ["xs", "ys", "zs", "xs'", ...] names (undefined :: [Bool]) = ["ps", "qs", "rs", "ps'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: [a] -> String # (Name a, Name b) => Name (Either a b) names (undefined :: Either Int Int) = ["exy", "exy1", ...] names (undefined :: Either Int Bool) = ["exp", "exp1", ...] Instance detailsDefined in Data.Express.Name Methodsname :: Either a b -> String # (Name a, Name b) => Name (a, b) names (undefined :: (Int,Int)) = ["xy", "zw", "xy'", ...] names (undefined :: (Bool,Bool)) = ["pq", "rs", "pq'", ...] Instance detailsDefined in Data.Express.Name Methodsname :: (a, b) -> String # Name (a -> b) names (undefined :: ()->()) = ["f", "g", "h", "f'", ...] names (undefined :: Int->Int) = ["f", "g", "h", ...] Instance detailsDefined in Data.Express.Name Methodsname :: (a -> b) -> String # (Name a, Name b, Name c) => Name (a, b, c) names (undefined :: (Int,Int,Int)) = ["xyz","uvw", ...] names (undefined :: (Int,Bool,Char)) = ["xpc", "xpc1", ...] Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c) -> String # (Name a, Name b, Name c, Name d) => Name (a, b, c, d) names (undefined :: ((),(),(),())) = ["uuuu", "uuuu1", ...] names (undefined :: (Int,Int,Int,Int)) = ["xxxx", ...] Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d) -> String # (Name a, Name b, Name c, Name d, Name e) => Name (a, b, c, d, e) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e) -> String # (Name a, Name b, Name c, Name d, Name e, Name f) => Name (a, b, c, d, e, f) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g) => Name (a, b, c, d, e, f, g) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h) => Name (a, b, c, d, e, f, g, h) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g, h) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h, Name i) => Name (a, b, c, d, e, f, g, h, i) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g, h, i) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h, Name i, Name j) => Name (a, b, c, d, e, f, g, h, i, j) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g, h, i, j) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h, Name i, Name j, Name k) => Name (a, b, c, d, e, f, g, h, i, j, k) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g, h, i, j, k) -> String # (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h, Name i, Name j, Name k, Name l) => Name (a, b, c, d, e, f, g, h, i, j, k, l) Instance detailsDefined in Data.Express.Name Methodsname :: (a, b, c, d, e, f, g, h, i, j, k, l) -> String #

class (Show a, Typeable a) => Express a where #

Express typeclass instances provide an expr function that allows values to be deeply encoded as applications of Exprs.

expr False  =  val False
expr (Just True)  =  value "Just" (Just :: Bool -> Maybe Bool) :$val True The function expr can be contrasted with the function val: • val always encodes values as atomic Value Exprs -- shallow encoding. • expr ideally encodes expressions as applications (:$) between Value Exprs -- deep encoding.

Depending on the situation, one or the other may be desirable.

Instances can be automatically derived using the TH function deriveExpress.

The following example shows a datatype and its instance:

data Stack a = Stack a (Stack a) | Empty
instance Express a => Express (Stack a) where
expr s@(Stack x y) = value "Stack" (Stack ->>: s) :$expr x :$ expr y
expr s@Empty       = value "Empty" (Empty   -: s)

To declare expr it may be useful to use auxiliary type binding operators: -:, ->:, ->>:, ->>>:, ->>>>:, ->>>>>:, ...

For types with atomic values, just declare  expr = val

Methods

expr :: a -> Expr #

Instances

Instances details
 Instance detailsDefined in Data.Express.Express Methodsexpr :: Int16 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Int32 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Int64 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Int8 -> Expr # Instance detailsDefined in Data.Express.Express Methods Instance detailsDefined in Data.Express.Express Methodsexpr :: Word16 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Word32 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Word64 -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Word8 -> Expr # Instance detailsDefined in Data.Express.Express Methods Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: A -> Expr # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: B -> Expr # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: C -> Expr # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: D -> Expr # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: E -> Expr # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: F -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Integer -> Expr # Express () Instance detailsDefined in Data.Express.Express Methodsexpr :: () -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Bool -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Char -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Double -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Float -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Int -> Expr # Instance detailsDefined in Data.Express.Express Methodsexpr :: Word -> Expr # (RealFloat a, Express a) => Express (Complex a) Instance detailsDefined in Data.Express.Express Methodsexpr :: Complex a -> Expr # (Integral a, Express a) => Express (Ratio a) Instance detailsDefined in Data.Express.Express Methodsexpr :: Ratio a -> Expr # Express a => Express (Maybe a) Instance detailsDefined in Data.Express.Express Methodsexpr :: Maybe a -> Expr # Express a => Express [a] Instance detailsDefined in Data.Express.Express Methodsexpr :: [a] -> Expr # (Express a, Express b) => Express (Either a b) Instance detailsDefined in Data.Express.Express Methodsexpr :: Either a b -> Expr # (Express a, Express b) => Express (a, b) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b) -> Expr # (Express a, Express b, Express c) => Express (a, b, c) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c) -> Expr # (Express a, Express b, Express c, Express d) => Express (a, b, c, d) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d) -> Expr # (Express a, Express b, Express c, Express d, Express e) => Express (a, b, c, d, e) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f) => Express (a, b, c, d, e, f) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g) => Express (a, b, c, d, e, f, g) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g, Express h) => Express (a, b, c, d, e, f, g, h) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g, h) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g, Express h, Express i) => Express (a, b, c, d, e, f, g, h, i) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g, h, i) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g, Express h, Express i, Express j) => Express (a, b, c, d, e, f, g, h, i, j) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g, h, i, j) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g, Express h, Express i, Express j, Express k) => Express (a, b, c, d, e, f, g, h, i, j, k) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g, h, i, j, k) -> Expr # (Express a, Express b, Express c, Express d, Express e, Express f, Express g, Express h, Express i, Express j, Express k, Express l) => Express (a, b, c, d, e, f, g, h, i, j, k, l) Instance detailsDefined in Data.Express.Express Methodsexpr :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Expr #

Derives an Conjurable instance for the given type Name.

This function needs the TemplateHaskell extension.

If -:, ->:, ->>:, ->>>:, ... are not in scope, this will derive them as well.

For now, this function only derives conjureEquality, conjureTiers and conjureExpress and does not derive conjureSubTypes, conjureArgumentCases and conjureSize. These will be added in future versions. If you plan to use features that depend on these functionalities, please define your instances manually.

Same as deriveConjurable but does not warn when instance already exists (deriveConjurable is preferable).

For now, this function only derives conjureEquality, conjureTiers and conjureExpress and does not derive conjureSubTypes, conjureArgumentCases and conjureSize. These will be added in future versions. If you plan to use features that depend on these functionalities, please define your instances manually.

Derives a Conjurable instance for a given type Name cascading derivation of type arguments as well.

For now, this function only derives conjureEquality, conjureTiers and conjureExpress and does not derive conjureSubTypes, conjureArgumentCases and conjureSize. These will be added in future versions. If you plan to use features that depend on these functionalities, please define your instances manually.

Pure interfaces

conjpure :: Conjurable f => String -> f -> [Prim] -> ([[Defn]], [[Defn]], [Expr], Thy) Source #

Like conjure but in the pure world.

1. tiers of implementations
2. tiers of candidates
3. a list of tests
4. the underlying theory

conjpureWith :: Conjurable f => Args -> String -> f -> [Prim] -> ([[Defn]], [[Defn]], [Expr], Thy) Source #

Like conjpure but allows setting options through Args and args.

Helper test types

data A #

Generic type A.

Can be used to test polymorphic functions with a type variable such as take or sort:

take :: Int -> [a] -> [a]
sort :: Ord a => [a] -> [a]

by binding them to the following types:

take :: Int -> [A] -> [A]
sort :: [A] -> [A]

This type is homomorphic to Nat6, B, C, D, E and F.

It is instance to several typeclasses so that it can be used to test functions with type contexts.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: A -> A #pred :: A -> A #toEnum :: Int -> A #fromEnum :: A -> Int #enumFrom :: A -> [A] #enumFromThen :: A -> A -> [A] #enumFromTo :: A -> A -> [A] #enumFromThenTo :: A -> A -> A -> [A] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (A, A) -> [A] #index :: (A, A) -> A -> Int #unsafeIndex :: (A, A) -> A -> Int #inRange :: (A, A) -> A -> Bool #rangeSize :: (A, A) -> Int #unsafeRangeSize :: (A, A) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: A -> A -> A #(-) :: A -> A -> A #(*) :: A -> A -> A #negate :: A -> A #abs :: A -> A #signum :: A -> A # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [A] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: A -> A -> A #rem :: A -> A -> A #div :: A -> A -> A #mod :: A -> A -> A #quotRem :: A -> A -> (A, A) #divMod :: A -> A -> (A, A) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> A -> ShowS #show :: A -> String #showList :: [A] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: A -> Maybe [[Expr]] Source #conjureCases :: A -> [Expr] Source #conjureArgumentCases :: A -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe A Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: A -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: A -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: A -> A -> Bool #(/=) :: A -> A -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: A -> A -> Ordering #(<) :: A -> A -> Bool #(<=) :: A -> A -> Bool #(>) :: A -> A -> Bool #(>=) :: A -> A -> Bool #max :: A -> A -> A #min :: A -> A -> A # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[A]] #list :: [A] #

data B #

Generic type B.

Can be used to test polymorphic functions with two type variables such as map or foldr:

map :: (a -> b) -> [a] -> [b]
foldr :: (a -> b -> b) -> b -> [a] -> b

by binding them to the following types:

map :: (A -> B) -> [A] -> [B]
foldr :: (A -> B -> B) -> B -> [A] -> B

This type is homomorphic to A, Nat6, C, D, E and F.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: B -> B #pred :: B -> B #toEnum :: Int -> B #fromEnum :: B -> Int #enumFrom :: B -> [B] #enumFromThen :: B -> B -> [B] #enumFromTo :: B -> B -> [B] #enumFromThenTo :: B -> B -> B -> [B] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (B, B) -> [B] #index :: (B, B) -> B -> Int #unsafeIndex :: (B, B) -> B -> Int #inRange :: (B, B) -> B -> Bool #rangeSize :: (B, B) -> Int #unsafeRangeSize :: (B, B) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: B -> B -> B #(-) :: B -> B -> B #(*) :: B -> B -> B #negate :: B -> B #abs :: B -> B #signum :: B -> B # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [B] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: B -> B -> B #rem :: B -> B -> B #div :: B -> B -> B #mod :: B -> B -> B #quotRem :: B -> B -> (B, B) #divMod :: B -> B -> (B, B) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> B -> ShowS #show :: B -> String #showList :: [B] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: B -> Maybe [[Expr]] Source #conjureCases :: B -> [Expr] Source #conjureArgumentCases :: B -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe B Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: B -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: B -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: B -> B -> Bool #(/=) :: B -> B -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: B -> B -> Ordering #(<) :: B -> B -> Bool #(<=) :: B -> B -> Bool #(>) :: B -> B -> Bool #(>=) :: B -> B -> Bool #max :: B -> B -> B #min :: B -> B -> B # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[B]] #list :: [B] #

data C #

Generic type C.

Can be used to test polymorphic functions with three type variables such as uncurry or zipWith:

uncurry :: (a -> b -> c) -> (a, b) -> c
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]

by binding them to the following types:

uncurry :: (A -> B -> C) -> (A, B) -> C
zipWith :: (A -> B -> C) -> [A] -> [B] -> [C]

This type is homomorphic to A, B, Nat6, D, E and F.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: C -> C #pred :: C -> C #toEnum :: Int -> C #fromEnum :: C -> Int #enumFrom :: C -> [C] #enumFromThen :: C -> C -> [C] #enumFromTo :: C -> C -> [C] #enumFromThenTo :: C -> C -> C -> [C] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (C, C) -> [C] #index :: (C, C) -> C -> Int #unsafeIndex :: (C, C) -> C -> Int #inRange :: (C, C) -> C -> Bool #rangeSize :: (C, C) -> Int #unsafeRangeSize :: (C, C) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: C -> C -> C #(-) :: C -> C -> C #(*) :: C -> C -> C #negate :: C -> C #abs :: C -> C #signum :: C -> C # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [C] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: C -> C -> C #rem :: C -> C -> C #div :: C -> C -> C #mod :: C -> C -> C #quotRem :: C -> C -> (C, C) #divMod :: C -> C -> (C, C) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> C -> ShowS #show :: C -> String #showList :: [C] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: C -> Maybe [[Expr]] Source #conjureCases :: C -> [Expr] Source #conjureArgumentCases :: C -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe C Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: C -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: C -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: C -> C -> Bool #(/=) :: C -> C -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: C -> C -> Ordering #(<) :: C -> C -> Bool #(<=) :: C -> C -> Bool #(>) :: C -> C -> Bool #(>=) :: C -> C -> Bool #max :: C -> C -> C #min :: C -> C -> C # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[C]] #list :: [C] #

data D #

Generic type D.

Can be used to test polymorphic functions with four type variables.

This type is homomorphic to A, B, C, Nat6, E and F.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: D -> D #pred :: D -> D #toEnum :: Int -> D #fromEnum :: D -> Int #enumFrom :: D -> [D] #enumFromThen :: D -> D -> [D] #enumFromTo :: D -> D -> [D] #enumFromThenTo :: D -> D -> D -> [D] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (D, D) -> [D] #index :: (D, D) -> D -> Int #unsafeIndex :: (D, D) -> D -> Int #inRange :: (D, D) -> D -> Bool #rangeSize :: (D, D) -> Int #unsafeRangeSize :: (D, D) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: D -> D -> D #(-) :: D -> D -> D #(*) :: D -> D -> D #negate :: D -> D #abs :: D -> D #signum :: D -> D # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [D] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: D -> D -> D #rem :: D -> D -> D #div :: D -> D -> D #mod :: D -> D -> D #quotRem :: D -> D -> (D, D) #divMod :: D -> D -> (D, D) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> D -> ShowS #show :: D -> String #showList :: [D] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: D -> Maybe [[Expr]] Source #conjureCases :: D -> [Expr] Source #conjureArgumentCases :: D -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe D Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: D -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: D -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: D -> D -> Bool #(/=) :: D -> D -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: D -> D -> Ordering #(<) :: D -> D -> Bool #(<=) :: D -> D -> Bool #(>) :: D -> D -> Bool #(>=) :: D -> D -> Bool #max :: D -> D -> D #min :: D -> D -> D # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[D]] #list :: [D] #

data E #

Generic type E.

Can be used to test polymorphic functions with five type variables.

This type is homomorphic to A, B, C, D, Nat6 and F.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: E -> E #pred :: E -> E #toEnum :: Int -> E #fromEnum :: E -> Int #enumFrom :: E -> [E] #enumFromThen :: E -> E -> [E] #enumFromTo :: E -> E -> [E] #enumFromThenTo :: E -> E -> E -> [E] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (E, E) -> [E] #index :: (E, E) -> E -> Int #unsafeIndex :: (E, E) -> E -> Int #inRange :: (E, E) -> E -> Bool #rangeSize :: (E, E) -> Int #unsafeRangeSize :: (E, E) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: E -> E -> E #(-) :: E -> E -> E #(*) :: E -> E -> E #negate :: E -> E #abs :: E -> E #signum :: E -> E # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [E] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: E -> E -> E #rem :: E -> E -> E #div :: E -> E -> E #mod :: E -> E -> E #quotRem :: E -> E -> (E, E) #divMod :: E -> E -> (E, E) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> E -> ShowS #show :: E -> String #showList :: [E] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: E -> Maybe [[Expr]] Source #conjureCases :: E -> [Expr] Source #conjureArgumentCases :: E -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe E Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: E -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: E -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: E -> E -> Bool #(/=) :: E -> E -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: E -> E -> Ordering #(<) :: E -> E -> Bool #(<=) :: E -> E -> Bool #(>) :: E -> E -> Bool #(>=) :: E -> E -> Bool #max :: E -> E -> E #min :: E -> E -> E # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[E]] #list :: [E] #

data F #

Generic type F.

Can be used to test polymorphic functions with five type variables.

This type is homomorphic to A, B, C, D, E and Nat6.

Instances

Instances details
 Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types Methodssucc :: F -> F #pred :: F -> F #toEnum :: Int -> F #fromEnum :: F -> Int #enumFrom :: F -> [F] #enumFromThen :: F -> F -> [F] #enumFromTo :: F -> F -> [F] #enumFromThenTo :: F -> F -> F -> [F] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsrange :: (F, F) -> [F] #index :: (F, F) -> F -> Int #unsafeIndex :: (F, F) -> F -> Int #inRange :: (F, F) -> F -> Bool #rangeSize :: (F, F) -> Int #unsafeRangeSize :: (F, F) -> Int # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(+) :: F -> F -> F #(-) :: F -> F -> F #(*) :: F -> F -> F #negate :: F -> F #abs :: F -> F #signum :: F -> F # Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsreadList :: ReadS [F] # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodsquot :: F -> F -> F #rem :: F -> F -> F #div :: F -> F -> F #mod :: F -> F -> F #quotRem :: F -> F -> (F, F) #divMod :: F -> F -> (F, F) # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods Instance detailsDefined in Test.LeanCheck.Utils.Types MethodsshowsPrec :: Int -> F -> ShowS #show :: F -> String #showList :: [F] -> ShowS # Source # Instance detailsDefined in Conjure.Conjurable MethodsconjureTiers :: F -> Maybe [[Expr]] Source #conjureCases :: F -> [Expr] Source #conjureArgumentCases :: F -> [[Expr]] Source #conjureEvaluate :: (Expr -> Expr) -> Int -> Defn -> Expr -> Maybe F Source # Source # Instance detailsDefined in Conjure.Expr Methodsexpr :: F -> Expr # Source # Instance detailsDefined in Conjure.Conjurable Methodsname :: F -> String # Instance detailsDefined in Test.LeanCheck.Utils.Types Methods(==) :: F -> F -> Bool #(/=) :: F -> F -> Bool # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodscompare :: F -> F -> Ordering #(<) :: F -> F -> Bool #(<=) :: F -> F -> Bool #(>) :: F -> F -> Bool #(>=) :: F -> F -> Bool #max :: F -> F -> F #min :: F -> F -> F # Instance detailsDefined in Test.LeanCheck.Utils.Types Methodstiers :: [[F]] #list :: [F] #