mono-traversable-0.6.1: Type classes for mapping, folding, and traversing monomorphic containers

Safe HaskellNone
LanguageHaskell2010

Data.MonoTraversable

Description

Type classes mirroring standard typeclasses, but working with monomorphic containers.

The motivation is that some commonly used data types (i.e., ByteString and Text) do not allow for instances of typeclasses like Functor and Foldable, since they are monomorphic structures. This module allows both monomorphic and polymorphic data types to be instances of the same typeclasses.

All of the laws for the polymorphic typeclasses apply to their monomorphic cousins. Thus, even though a MonoFunctor instance for Set could theoretically be defined, it is omitted since it could violate the functor law of omap f . omap g = omap (f . g).

Note that all typeclasses have been prefixed with Mono, and functions have been prefixed with o. The mnemonic for o is "only one," or alternatively "it's mono, but m is overused in Haskell, so we'll use the second letter instead." (Agreed, it's not a great mangling scheme, input is welcome!)

Synopsis

Documentation

type family Element mono

Instances

type Element ByteString = Word8 
type Element ByteString = Word8 
type Element IntSet = Int 
type Element Text = Char 
type Element Text = Char 
type Element [a] = a 
type Element (IO a) = a 
type Element (ZipList a) = a 
type Element (Maybe a) = a 
type Element (Identity a) = a 
type Element (IntMap a) = a 
type Element (Set e) = e 
type Element (Tree a) = a 
type Element (Seq a) = a 
type Element (ViewL a) = a 
type Element (ViewR a) = a 
type Element (DList a) = a 
type Element (Option a) = a 
type Element (NonEmpty a) = a 
type Element (HashSet e) = e 
type Element (Vector a) = a 
type Element (Vector a) = a 
type Element (Vector a) = a 
type Element (r -> a) = a 
type Element (Either a b) = b 
type Element (a, b) = b 
type Element (Const m a) = a 
type Element (WrappedMonad m a) = a 
type Element (IdentityT m a) = a 
type Element (Map k v) = v 
type Element (ListT m a) = a 
type Element (WrappedApplicative f a) = a 
type Element (MaybeApply f a) = a 
type Element (MaybeT m a) = a 
type Element (HashMap k v) = v 
type Element (MinLen nat mono) = Element mono 
type Element (WrappedArrow a b c) = c 
type Element (Cokleisli w a b) = b 
type Element (ContT r m a) = a 
type Element (ErrorT e m a) = a 
type Element (ReaderT r m a) = a 
type Element (StateT s m a) = a 
type Element (StateT s m a) = a 
type Element (WriterT w m a) = a 
type Element (WriterT w m a) = a 
type Element (Compose f g a) = a 
type Element (Static f a b) = b 
type Element (Product f g a) = a 
type Element (RWST r w s m a) = a 
type Element (RWST r w s m a) = a 

class MonoFunctor mono where

Minimal complete definition

Nothing

Methods

omap :: (Element mono -> Element mono) -> mono -> mono

Instances

MonoFunctor ByteString 
MonoFunctor ByteString 
MonoFunctor Text 
MonoFunctor Text 
MonoFunctor [a] 
MonoFunctor (IO a) 
MonoFunctor (ZipList a) 
MonoFunctor (Maybe a) 
MonoFunctor (Identity a) 
MonoFunctor (IntMap a) 
MonoFunctor (Tree a) 
MonoFunctor (Seq a) 
MonoFunctor (ViewL a) 
MonoFunctor (ViewR a) 
MonoFunctor (DList a) 
MonoFunctor (Option a) 
MonoFunctor (NonEmpty a) 
MonoFunctor (Vector a) 
Unbox a => MonoFunctor (Vector a) 
Storable a => MonoFunctor (Vector a) 
MonoFunctor (r -> a) 
MonoFunctor (Either a b) 
MonoFunctor (a, b) 
MonoFunctor (Const m a) 
Monad m => MonoFunctor (WrappedMonad m a) 
Functor m => MonoFunctor (IdentityT m a) 
MonoFunctor (Map k v) 
Functor m => MonoFunctor (ListT m a) 
Functor f => MonoFunctor (WrappedApplicative f a) 
Functor f => MonoFunctor (MaybeApply f a) 
Functor m => MonoFunctor (MaybeT m a) 
MonoFunctor (HashMap k v) 
MonoFunctor mono => MonoFunctor (MinLen nat mono) 
Arrow a => MonoFunctor (WrappedArrow a b c) 
MonoFunctor (Cokleisli w a b) 
Functor m => MonoFunctor (ContT r m a) 
Functor m => MonoFunctor (ErrorT e m a) 
Functor m => MonoFunctor (ReaderT r m a) 
Functor m => MonoFunctor (StateT s m a) 
Functor m => MonoFunctor (StateT s m a) 
Functor m => MonoFunctor (WriterT w m a) 
Functor m => MonoFunctor (WriterT w m a) 
(Functor f, Functor g) => MonoFunctor (Compose f g a) 
Functor f => MonoFunctor (Static f a b) 
(Functor f, Functor g) => MonoFunctor (Product f g a) 
Functor m => MonoFunctor (RWST r w s m a) 
Functor m => MonoFunctor (RWST r w s m a) 

class MonoFoldable mono where

Minimal complete definition

Nothing

Methods

ofoldMap :: Monoid m => (Element mono -> m) -> mono -> m

ofoldr :: (Element mono -> b -> b) -> b -> mono -> b

ofoldl' :: (a -> Element mono -> a) -> a -> mono -> a

otoList :: mono -> [Element mono]

oall :: (Element mono -> Bool) -> mono -> Bool

oany :: (Element mono -> Bool) -> mono -> Bool

onull :: mono -> Bool

olength :: mono -> Int

olength64 :: mono -> Int64

ocompareLength :: Integral i => mono -> i -> Ordering

otraverse_ :: (MonoFoldable mono, Applicative f) => (Element mono -> f b) -> mono -> f ()

ofor_ :: (MonoFoldable mono, Applicative f) => mono -> (Element mono -> f b) -> f ()

omapM_ :: (MonoFoldable mono, Monad m) => (Element mono -> m ()) -> mono -> m ()

oforM_ :: (MonoFoldable mono, Monad m) => mono -> (Element mono -> m ()) -> m ()

ofoldlM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a

ofoldMap1Ex :: Semigroup m => (Element mono -> m) -> mono -> m

Note: this is a partial function. On an empty MonoFoldable, it will throw an exception. See Data.NonNull for a total version of this function.

ofoldr1Ex :: (Element mono -> Element mono -> Element mono) -> mono -> Element mono

Note: this is a partial function. On an empty MonoFoldable, it will throw an exception. See Data.NonNull for a total version of this function.

ofoldl1Ex' :: (Element mono -> Element mono -> Element mono) -> mono -> Element mono

Note: this is a partial function. On an empty MonoFoldable, it will throw an exception. See Data.NonNull for a total version of this function.

headEx :: mono -> Element mono

lastEx :: mono -> Element mono

unsafeHead :: mono -> Element mono

unsafeLast :: mono -> Element mono

maximumByEx :: (Element mono -> Element mono -> Ordering) -> mono -> Element mono

minimumByEx :: (Element mono -> Element mono -> Ordering) -> mono -> Element mono

headMay :: MonoFoldable mono => mono -> Maybe (Element mono)

like Data.List.head, but not partial

lastMay :: MonoFoldable mono => mono -> Maybe (Element mono)

like Data.List.last, but not partial

osum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono

The sum function computes the sum of the numbers of a structure.

oproduct :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono

The product function computes the product of the numbers of a structure.

oand :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool

Are all of the values True?

Since 0.6.0

oor :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool

Are any of the values True?

Since 0.6.0

class (MonoFoldable mono, Monoid mono) => MonoFoldableMonoid mono where

Minimal complete definition

Nothing

Methods

oconcatMap :: (Element mono -> mono) -> mono -> mono

class (MonoFoldable mono, Ord (Element mono)) => MonoFoldableOrd mono where

A typeclass for MonoFoldables containing elements which are an instance of Ord.

Minimal complete definition

Nothing

Methods

maximumEx :: mono -> Element mono

minimumEx :: mono -> Element mono

maximumMay :: MonoFoldableOrd mono => mono -> Maybe (Element mono)

maximumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono)

minimumMay :: MonoFoldableOrd mono => mono -> Maybe (Element mono)

minimumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono)

ofor :: (MonoTraversable mono, Applicative f) => mono -> (Element mono -> f (Element mono)) -> f mono

oforM :: (MonoTraversable mono, Monad f) => mono -> (Element mono -> f (Element mono)) -> f mono

ofoldlUnwrap :: MonoFoldable mono => (x -> Element mono -> x) -> x -> (x -> b) -> mono -> b

A strict left fold, together with an unwrap function.

This is convenient when the accumulator value is not the same as the final expected type. It is provided mainly for integration with the foldl package, to be used in conjunction with purely.

Since 0.3.1

ofoldMUnwrap :: (Monad m, MonoFoldable mono) => (x -> Element mono -> m x) -> m x -> (x -> m b) -> mono -> m b

A monadic strict left fold, together with an unwrap function.

Similar to foldlUnwrap, but allows monadic actions. To be used with impurely from foldl.

Since 0.3.1

class MonoPointed mono where

Instances must obey the laws:

  • otoList . mconcat . map opoint == id

Methods

opoint :: Element mono -> mono