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:
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]
fromJust function extracts the element out of a
throws an error if its argument is
maybeToList function returns an empty list when given
Nothing or a singleton list when not given
listToMaybe function returns
Nothing on an empty list
a is the first element of the list.