| Stability | experimental |
|---|---|
| Maintainer | dons@galois.com |
Data.Adaptive.Maybe
Description
Self optimzing sum types.
This library statically adapts the polymorphic container representation of Maybe to specific, more efficient representations, when instantiated with particular monomorphic types. It does this via an associated more efficient data type for each pair of elements you wish to store in your container.
That is, instead of representing 'Maybe Int' as:
Just
|
I# 3#
A self-optimizing pair will unpack the constructors, yielding this data representation:
JustInt 3#
Saving an indirection. The resulting structure should be both more time and space efficient than the generic polymorphic container it is derived from.
Self adaptive polymorphic containers are able to unpack their components, something not possible with, for example, strict polymorphic containers.
- class AdaptMaybe a where
- isNothing :: AdaptMaybe a => Maybe a -> Bool
- fromJust :: AdaptMaybe a => Maybe a -> a
- fromMaybe :: AdaptMaybe a => a -> Maybe a -> a
- maybeToList :: AdaptMaybe a => Maybe a -> [a]
- listToMaybe :: AdaptMaybe a => [a] -> Maybe a
- catMaybes :: AdaptMaybe a => [Maybe a] -> [a]
- mapMaybe :: AdaptMaybe b => (a -> Maybe b) -> [a] -> [b]
Documentation
isNothing :: AdaptMaybe a => Maybe a -> BoolSource
fromJust :: AdaptMaybe a => Maybe a -> aSource
The fromJust function extracts the element out of a Just and
throws an error if its argument is Nothing.
fromMaybe :: AdaptMaybe a => a -> Maybe a -> aSource
maybeToList :: AdaptMaybe a => Maybe a -> [a]Source
The maybeToList function returns an empty list when given
Nothing or a singleton list when not given Nothing.
listToMaybe :: AdaptMaybe a => [a] -> Maybe aSource
The listToMaybe function returns Nothing on an empty list
or where Just aa is the first element of the list.
catMaybes :: AdaptMaybe a => [Maybe a] -> [a]Source
mapMaybe :: AdaptMaybe b => (a -> Maybe b) -> [a] -> [b]Source