RepLib-0.5.3.3: Generic programming library with representation types

LicenseBSD
Maintainersweirich@cis.upenn.edu
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Generics.RepLib.Lib

Contents

Description

A library of type-indexed functions

Synopsis

Available for all representable types

subtrees :: forall a. Rep a => a -> [a] Source

Produce all children of a datastructure with the same type. Note that subtrees is available for all representable types. For those that are not recursive datatypes, subtrees will always return the empty list. But, these trivial instances are convenient to have for the Shrink operation below.

deepSeq :: Rep a => a -> b -> b Source

Recursively force the evaluation of the first argument. For example, deepSeq ( x , y ) z where x = ... y = ... will evaluate both x and y then return z

rnf :: Rep a => a -> a Source

Force the evaluation of *datatypes* to their normal forms. Other types are left alone and not forced.

Specializable type-indexed functions

class Rep1 GSumD a => GSum a where Source

Add together all of the Ints in a datastructure For example: gsum ( 1 , True, ("a", Maybe 3, []) , Nothing) 4

Minimal complete definition

Nothing

Methods

gsum :: a -> Int Source

Instances

GSum Bool 
GSum Char 
GSum Double 
GSum Float 
GSum Int 
GSum Integer 
GSum () 
GSum a => GSum [a] 
GSum a => GSum (Set a) 
(GSum a, GSum b) => GSum (a, b) 
(Rep k, GSum a) => GSum (Map k a) 

class Rep1 ZeroD a => Zero a where Source

Create a zero element of a type ( zero :: ((Int, Maybe Int), Float)) ((0, Nothing), 0.0)

Minimal complete definition

Nothing

Methods

zero :: a Source

Instances

Zero Bool 
Zero Char 
Zero Double 
Zero Float 
Zero Int 
Zero Integer 
Zero () 
Zero IOError 
Zero a => Zero [a] 
Rep a => Zero (Set a) 
(Zero a, Zero b) => Zero (a -> b) 
(Zero a, Zero b) => Zero (a, b) 
(Rep k, Rep a) => Zero (Map k a) 

class Rep1 GenerateD a => Generate a where Source

Generate elements of a type up to a certain depth

Minimal complete definition

Nothing

Methods

generate :: Int -> [a] Source

class Rep1 EnumerateD a => Enumerate a where Source

enumerate the elements of a type, in DFS order.

Minimal complete definition

Nothing

Methods

enumerate :: [a] Source

class Rep1 ShrinkD a => Shrink a where Source

Given an element, return smaller elements of the same type for example, to automatically find small counterexamples when testing

Minimal complete definition

Nothing

Methods

shrink :: a -> [a] Source

Instances

Shrink Char 
Shrink Int 
Shrink () 
Shrink a => Shrink [a] 
(Ord a, Shrink a) => Shrink (Set a) 
(Shrink a, Shrink b) => Shrink (a, b) 
(Ord k, Shrink k, Shrink a) => Shrink (Map k a) 

class Rep1 (LreduceD b) a => Lreduce b a where Source

A general version of fold left, use for Fold class below

Minimal complete definition

Nothing

Methods

lreduce :: b -> a -> b Source

Instances

Lreduce b Bool 
Lreduce b Char 
Lreduce b () 
Lreduce b Int 
(Ord a, Lreduce b a) => Lreduce b (Set a) 
Lreduce c a => Lreduce c [a] 
(Lreduce c a, Lreduce c b) => Lreduce c (a, b) 

class Rep1 (RreduceD b) a => Rreduce b a where Source

A general version of fold right, use for Fold class below

Minimal complete definition

Nothing

Methods

rreduce :: a -> b -> b Source

Instances

Rreduce b Bool 
Rreduce b Char 
Rreduce b () 
Rreduce b Int 
(Ord a, Rreduce b a) => Rreduce b (Set a) 
Rreduce c a => Rreduce c [a] 
(Rreduce c a, Rreduce c b) => Rreduce c (a, b) 

Generic operations based on Fold

class Fold f where Source

All of the functions below are defined using instances of the following class

Methods

foldRight :: Rep a => (a -> b -> b) -> f a -> b -> b Source

foldLeft :: Rep a => (b -> a -> b) -> b -> f a -> b Source

Instances

Fold [] 
Fold Set 
Fold (Map k) 

crush :: (Rep a, Fold t) => (a -> a -> a) -> a -> t a -> a Source

Fold a bindary operation left over a datastructure

gproduct :: (Rep a, Num a, Fold t) => t a -> a Source

Multiply all elements together

gand :: Fold t => t Bool -> Bool Source

Ensure all booleans are true

gor :: Fold t => t Bool -> Bool Source

Ensure at least one boolean is true

flatten :: (Rep a, Fold t) => t a -> [a] Source

Convert to list

count :: (Rep a, Fold t) => t a -> Int Source

Count number of as that appear in the argument

comp :: (Rep a, Fold t) => t (a -> a) -> a -> a Source

Compose all functions in the datastructure together

gconcat :: (Rep a, Fold t) => t [a] -> [a] Source

Concatenate all lists in the datastructure together

gall :: (Rep a, Fold t) => (a -> Bool) -> t a -> Bool Source

Ensure property holds of all data

gany :: (Rep a, Fold t) => (a -> Bool) -> t a -> Bool Source

Ensure property holds of some element

gelem :: (Rep a, Eq a, Fold t) => a -> t a -> Bool Source

Is an element stored in a datastructure

Auxiliary types and generators for derivable classes

data GSumD a Source

Constructors

GSumD 

Fields

gsumD :: a -> Int
 

Instances

GSum a => Sat (GSumD a) 

data ZeroD a Source

Constructors

ZD 

Fields

zeroD :: a
 

Instances

Zero a => Sat (ZeroD a) 

data GenerateD a Source

Constructors

GenerateD 

Fields

generateD :: Int -> [a]
 

Instances

data EnumerateD a Source

Constructors

EnumerateD 

Fields

enumerateD :: [a]
 

Instances

data ShrinkD a Source

Constructors

ShrinkD 

Fields

shrinkD :: a -> [a]
 

Instances

Shrink a => Sat (ShrinkD a) 

data LreduceD b a Source

Constructors

LreduceD 

Fields

lreduceD :: b -> a -> b
 

Instances

Lreduce b a => Sat (LreduceD b a) 

data RreduceD b a Source

Constructors

RreduceD 

Fields

rreduceD :: a -> b -> b
 

Instances

Rreduce b a => Sat (RreduceD b a) 

rnfR :: R a -> a -> a Source

deepSeqR :: R a -> a -> b -> b Source

gsumR1 :: R1 GSumD a -> a -> Int Source

zeroR1 :: R1 ZeroD a -> a Source

lreduceR1 :: R1 (LreduceD b) a -> b -> a -> b Source

rreduceR1 :: R1 (RreduceD b) a -> a -> b -> b Source