adaptive-containers-0.3: Self optimizing container types

Stabilityexperimental
Maintainerdons@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.

Synopsis

Documentation

class AdaptMaybe a whereSource

Associated Types

data Maybe a Source

Methods

just :: a -> Maybe aSource

nothing :: Maybe aSource

isJust :: Maybe a -> BoolSource

The isJust function returns True iff its argument is of the form Just _.

maybe :: b -> (a -> b) -> Maybe a -> bSource

isNothing :: AdaptMaybe a => Maybe a -> BoolSource

The isNothing function returns True iff its argument is Nothing.

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

The fromMaybe function takes a default value and and Maybe value. If the Maybe is Nothing, it returns the default values; otherwise, it returns the value contained in the Maybe.

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 Just a where a is the first element of the list.

catMaybes :: AdaptMaybe a => [Maybe a] -> [a]Source

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

mapMaybe :: AdaptMaybe b => (a -> Maybe b) -> [a] -> [b]Source

The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it just Just b, then b is included in the result list.