Safe Haskell | None |
---|---|
Language | Haskell2010 |
- reifyFunction :: Enumerable a => (a -> b) -> [(a, b)]
- reifyFunctionAt :: [a] -> (a -> b) -> [(a, b)]
- reifyFunctionM :: Enumerable a => (forall m. MonadThrow m => a -> m b) -> [(a, b)]
- reifyFunctionAtM :: [a] -> Partial a b -> [(a, b)]
- reifyPredicateAt :: [a] -> (a -> Bool) -> [a]
- reifyFunctionMaybeAt :: [a] -> (a -> Maybe b) -> [(a, b)]
- reifyFunctionListAt :: [a] -> (a -> [b]) -> [(a, b)]
- reifyFunctionEitherAt :: [a] -> (a -> Either SomeException b) -> [(a, b)]
- reifyFunctionSpoonAt :: NFData b => [a] -> (a -> b) -> [(a, b)]
- reifyFunction2 :: (Enumerable a, Enumerable b) => (a -> b -> c) -> [(a, [(b, c)])]
- reifyFunction2At :: [a] -> [b] -> (a -> b -> c) -> [(a, [(b, c)])]
- reifyFunction2M :: (Enumerable a, Enumerable b) => (forall m. MonadThrow m => a -> b -> m c) -> [(a, [(b, c)])]
- reifyFunction2AtM :: [a] -> [b] -> (forall m. MonadThrow m => a -> b -> m c) -> [(a, [(b, c)])]
Documentation
reifyFunction :: Enumerable a => (a -> b) -> [(a, b)] Source
reify a total function.
>>> reifyFunction not -- Prelude not
[(False,True),(True,False)]
reifyFunctionAt :: [a] -> (a -> b) -> [(a, b)] Source
reify a total function at any subset of the domain.
reifyFunctionM :: Enumerable a => (forall m. MonadThrow m => a -> m b) -> [(a, b)] Source
reify a (safely-)partial function into a map (which is implicitly partial, where Map.lookup
is like ($)
.
reifyFunctionAtM :: [a] -> Partial a b -> [(a, b)] Source
reify a (safely-)partial function at any domain.
use the functions suffixed with M
when your function is explicitly partial,
i.e. of type (forall m. MonadThrow m => a -> m b)
.
when inside a function arrow, like:
reifyFunctionAtM :: [a] -> (forall m. MonadThrow m => a -> m b) -> [(a,b)] reifyFunctionAtM domain f = ...
the Rank2
type (and non-concrete types) means that f
can only use
parametric polymorphic functions, or the methods of the MonadThrow
class
(namely throwM
), or methods of MonadThrow
superclasses (namely return
, et cetera).
MonadThrow
is a class from the exceptions
package that generalizes failibility.
it has instances for Maybe
, Either
, []
, IO
, and more.
use the functions suffixed with At
when your domain isn't Enumerable
,
or when you want to restrict the domain.
the most general function in this module.
>>>
:{
let uppercasePartial :: (MonadThrow m) => Char -> m Char uppercasePartial c = case c of 'a' -> return 'A' 'b' -> return 'B' 'z' -> return 'Z' _ -> failed "uppercasePartial" :}
>>> reifyFunctionAtM ['a'..'c'] uppercasePartial [(a
,A
),(b
,B
)]
if your function doesn't fail under MonadThrow
, see:
reifyFunctionAtMaybe
reifyFunctionAtList
reifyFunctionAtEither
reifyPredicateAt :: [a] -> (a -> Bool) -> [a] Source
reifyFunctionMaybeAt :: [a] -> (a -> Maybe b) -> [(a, b)] Source
reify a (safely-)partial function that fails specifically under Maybe
.
reifyFunctionListAt :: [a] -> (a -> [b]) -> [(a, b)] Source
reify a (safely-)partial function that fails specifically under []
.
reifyFunctionEitherAt :: [a] -> (a -> Either SomeException b) -> [(a, b)] Source
reify a (safely-)partial function that fails specifically under Either SomeException
.
reifyFunctionSpoonAt :: NFData b => [a] -> (a -> b) -> [(a, b)] Source
reifies an *unsafely*-partial function (i.e. a function that throws exceptions or that has inexhaustive pattern matching).
forces the function to be strict.
>>>
import Data.Ratio (Ratio)
>>>
fmap (1/) [0..3 :: Ratio Integer]
[*** Exception: Ratio has zero denominator
>>>
let (1/) = reciprocal
>>>
reifyFunctionSpoonAt [0..3 :: Ratio Integer] reciprocal
[(1 % 1,1 % 1),(2 % 1,1 % 2),(3 % 1,1 % 3)]
normal caveats from violating purity (via unsafePerformIO
) and from catchalls (via (e :: SomeExceptions -> _)
) apply.
reifyFunction2 :: (Enumerable a, Enumerable b) => (a -> b -> c) -> [(a, [(b, c)])] Source
reify a binary total function
reifyFunction2At :: [a] -> [b] -> (a -> b -> c) -> [(a, [(b, c)])] Source
reify a binary total function at some domain
reifyFunction2M :: (Enumerable a, Enumerable b) => (forall m. MonadThrow m => a -> b -> m c) -> [(a, [(b, c)])] Source
reify a binary (safely-)partial function
reifyFunction2AtM :: [a] -> [b] -> (forall m. MonadThrow m => a -> b -> m c) -> [(a, [(b, c)])] Source
reify a binary (safely-)partial function at some domain