enumerate-function-0.0.1: simple package for inverting functions and testing totality, via brute enumeration of the domain

Safe HaskellNone
LanguageHaskell2010

Enumerate.Orphans.Function

Contents

Description

orphan instances, of 'Enumerate'\/'Eq'\/'Show', for functions:

  • instance (Enumerable a, Enumerable b, Ord a,  Ord b)  => Enumerable (a -> b)
  • instance (Enumerable a,               Eq b)           => Eq         (a -> b)
  • instance (Enumerable a,               Show a, Show b) => Show       (a -> b)

see:

(that are included for completeness, but not exported by default (i.e. by Enumerate). you probably want build-time instance-resolution errors, rather than possible runtime non-termination).

-- doctest
>>> :set -XLambdaCase

Synopsis

Documentation

Orphan instances

(Enumerable a, Eq b) => Eq (a -> b) Source #

brute-force function extensionality.

warning: the size of the domain grows exponentially in the number of arguments.

>>> (\case LT -> False; EQ -> False; GT -> False) == const False
True
>>> (\case LT -> False; EQ -> False; GT -> False) == const True
False

because functions are curried, the instance is recursive, and it works on functions of any arity:

 -- De Morgan's laws
>> (\x y -> not (x && y)) == (\x y -> not x || not y)

True >>> (x y -> not (x || y)) == (x y -> not x && not y) True

Methods

(==) :: (a -> b) -> (a -> b) -> Bool #

(/=) :: (a -> b) -> (a -> b) -> Bool #

(Enumerable a, Show a, Show b) => Show (a -> b) Source #
  • - >>> not
  • - unsafeFromList [(False,True),(True,False)]

because functions are curried, the instance is recursive, and it works on functions of any arity:

  • - >>> (&&)
  • - unsafeFromList [(False,unsafeFromList [(False,False),(True,False)]),(True,unsafeFromList [(False,False),(True,True)])]

Methods

showsPrec :: Int -> (a -> b) -> ShowS #

show :: (a -> b) -> String #

showList :: [a -> b] -> ShowS #

(Enumerable a, Enumerable b, Ord a, Ord b) => Enumerable (a -> b) Source #

the exponential type.

the cardinality is the cardinality of b raised to the cardinality a, i.e. |b|^|a|.

warning: it grows very quickly.

might be useful for generating random functions on small types, like to fuzz test type class laws.

the cardinality call is efficient (depending on the efficiency of the base type's call). you should be able to safely (WRT performance) call enumerateBelow, unless the arithmetic itself becomes too expensive.

instance (Enumerable a, Enumerable b, Ord a, Ord b) => Enumerable (a -> b) where
 enumerated = functionEnumerated

Methods

enumerated :: [a -> b] #

cardinality :: proxy (a -> b) -> Natural #