Safe Haskell | None |
---|---|
Language | Haskell2010 |
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!)
- type family Element mono
- class MonoFunctor mono where
- class MonoFoldable mono where
- 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
- ofoldr1Ex :: (Element mono -> Element mono -> Element mono) -> mono -> Element mono
- ofoldl1Ex' :: (Element mono -> Element mono -> Element mono) -> mono -> Element mono
- 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)
- lastMay :: MonoFoldable mono => mono -> Maybe (Element mono)
- osum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
- oproduct :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono
- oand :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool
- oor :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool
- class (MonoFoldable mono, Monoid mono) => MonoFoldableMonoid mono where
- oconcatMap :: (Element mono -> mono) -> mono -> mono
- class (MonoFoldable mono, Ord (Element mono)) => MonoFoldableOrd mono where
- 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)
- class (MonoFunctor mono, MonoFoldable mono) => MonoTraversable mono where
- 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
- ofoldMUnwrap :: (Monad m, MonoFoldable mono) => (x -> Element mono -> m x) -> m x -> (x -> m b) -> mono -> m b
- class MonoPointed mono where
Documentation
type family Element mono Source
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 (ReaderT r m a) = a | |
type Element (StateT s m a) = a | |
type Element (StateT s m a) = a | |
type Element (ErrorT e 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 Source
Nothing
class MonoFoldable mono where Source
Nothing
ofoldMap :: Monoid m => (Element mono -> m) -> mono -> m Source
ofoldr :: (Element mono -> b -> b) -> b -> mono -> b Source
ofoldl' :: (a -> Element mono -> a) -> a -> mono -> a Source
otoList :: mono -> [Element mono] Source
oall :: (Element mono -> Bool) -> mono -> Bool Source
oany :: (Element mono -> Bool) -> mono -> Bool Source
olength64 :: mono -> Int64 Source
ocompareLength :: Integral i => mono -> i -> Ordering Source
otraverse_ :: (MonoFoldable mono, Applicative f) => (Element mono -> f b) -> mono -> f () Source
ofor_ :: (MonoFoldable mono, Applicative f) => mono -> (Element mono -> f b) -> f () Source
omapM_ :: (MonoFoldable mono, Monad m) => (Element mono -> m ()) -> mono -> m () Source
oforM_ :: (MonoFoldable mono, Monad m) => mono -> (Element mono -> m ()) -> m () Source
ofoldlM :: (MonoFoldable mono, Monad m) => (a -> Element mono -> m a) -> a -> mono -> m a Source
ofoldMap1Ex :: Semigroup m => (Element mono -> m) -> mono -> m Source
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 Source
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 Source
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 Source
lastEx :: mono -> Element mono Source
unsafeHead :: mono -> Element mono Source
unsafeLast :: mono -> Element mono Source
maximumByEx :: (Element mono -> Element mono -> Ordering) -> mono -> Element mono Source
minimumByEx :: (Element mono -> Element mono -> Ordering) -> mono -> Element mono Source
MonoFoldable ByteString | |
MonoFoldable ByteString | |
MonoFoldable IntSet | |
MonoFoldable Text | |
MonoFoldable Text | |
MonoFoldable [a] | |
MonoFoldable (Maybe a) | |
MonoFoldable (Identity a) | |
MonoFoldable (IntMap a) | |
MonoFoldable (Set e) | |
MonoFoldable (Tree a) | |
MonoFoldable (Seq a) | |
MonoFoldable (ViewL a) | |
MonoFoldable (ViewR a) | |
MonoFoldable (DList a) | |
MonoFoldable (Option a) | |
MonoFoldable (NonEmpty a) | |
MonoFoldable (HashSet e) | |
MonoFoldable (Vector a) | |
Unbox a => MonoFoldable (Vector a) | |
Storable a => MonoFoldable (Vector a) | |
MonoFoldable (Either a b) | |
MonoFoldable (Map k v) | |
MonoFoldable (HashMap k v) | |
MonoFoldable mono => MonoFoldable (MinLen nat mono) |
headMay :: MonoFoldable mono => mono -> Maybe (Element mono) Source
like Data.List.head, but not partial
lastMay :: MonoFoldable mono => mono -> Maybe (Element mono) Source
like Data.List.last, but not partial
osum :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono Source
The sum
function computes the sum of the numbers of a structure.
oproduct :: (MonoFoldable mono, Num (Element mono)) => mono -> Element mono Source
The product
function computes the product of the numbers of a structure.
oand :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool Source
Are all of the values True
?
Since 0.6.0
oor :: (Element mono ~ Bool, MonoFoldable mono) => mono -> Bool Source
Are any of the values True
?
Since 0.6.0
class (MonoFoldable mono, Monoid mono) => MonoFoldableMonoid mono where Source
Nothing
oconcatMap :: (Element mono -> mono) -> mono -> mono Source
MonoFoldableMonoid ByteString | |
MonoFoldableMonoid ByteString | |
MonoFoldableMonoid Text | |
MonoFoldableMonoid Text | |
(MonoFoldable (t a), Monoid (t a)) => MonoFoldableMonoid (t a) |
class (MonoFoldable mono, Ord (Element mono)) => MonoFoldableOrd mono where Source
A typeclass for MonoFoldable
s containing elements which are an instance
of Ord
.
Nothing
MonoFoldableOrd ByteString | |
MonoFoldableOrd ByteString | |
MonoFoldableOrd IntSet | |
MonoFoldableOrd Text | |
MonoFoldableOrd Text | |
Ord a => MonoFoldableOrd [a] | |
Ord a => MonoFoldableOrd (Maybe a) | |
Ord a => MonoFoldableOrd (Identity a) | |
Ord a => MonoFoldableOrd (IntMap a) | |
Ord e => MonoFoldableOrd (Set e) | |
Ord a => MonoFoldableOrd (Tree a) | |
Ord a => MonoFoldableOrd (Seq a) | |
Ord a => MonoFoldableOrd (ViewL a) | |
Ord a => MonoFoldableOrd (ViewR a) | |
Ord a => MonoFoldableOrd (Option a) | |
Ord a => MonoFoldableOrd (NonEmpty a) | |
Ord e => MonoFoldableOrd (HashSet e) | |
Ord a => MonoFoldableOrd (Vector a) | |
(Unbox a, Ord a) => MonoFoldableOrd (Vector a) | |
(Ord a, Storable a) => MonoFoldableOrd (Vector a) | |
Ord b => MonoFoldableOrd (Either a b) | |
Ord v => MonoFoldableOrd (Map k v) | |
Ord v => MonoFoldableOrd (HashMap k v) | |
MonoFoldableOrd mono => MonoFoldableOrd (MinLen nat mono) |
maximumMay :: MonoFoldableOrd mono => mono -> Maybe (Element mono) Source
maximumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono) Source
minimumMay :: MonoFoldableOrd mono => mono -> Maybe (Element mono) Source
minimumByMay :: MonoFoldable mono => (Element mono -> Element mono -> Ordering) -> mono -> Maybe (Element mono) Source
class (MonoFunctor mono, MonoFoldable mono) => MonoTraversable mono where Source
Nothing
otraverse :: Applicative f => (Element mono -> f (Element mono)) -> mono -> f mono Source
omapM :: Monad m => (Element mono -> m (Element mono)) -> mono -> m mono Source
MonoTraversable ByteString | |
MonoTraversable ByteString | |
MonoTraversable Text | |
MonoTraversable Text | |
MonoTraversable [a] | |
MonoTraversable (Maybe a) | |
MonoTraversable (Identity a) | |
MonoTraversable (IntMap a) | |
MonoTraversable (Tree a) | |
MonoTraversable (Seq a) | |
MonoTraversable (ViewL a) | |
MonoTraversable (ViewR a) | |
MonoTraversable (DList a) | |
MonoTraversable (Option a) | |
MonoTraversable (NonEmpty a) | |
MonoTraversable (Vector a) | |
Unbox a => MonoTraversable (Vector a) | |
Storable a => MonoTraversable (Vector a) | |
MonoTraversable (Either a b) | |
MonoTraversable (Map k v) | |
MonoTraversable (HashMap k v) | |
MonoTraversable mono => MonoTraversable (MinLen nat mono) |
ofor :: (MonoTraversable mono, Applicative f) => mono -> (Element mono -> f (Element mono)) -> f mono Source
oforM :: (MonoTraversable mono, Monad f) => mono -> (Element mono -> f (Element mono)) -> f mono Source
ofoldlUnwrap :: MonoFoldable mono => (x -> Element mono -> x) -> x -> (x -> b) -> mono -> b Source
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 Source
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 Source
Instances must obey the laws:
otoList . mconcat . map opoint == id
MonoPointed ByteString | |
MonoPointed ByteString | |
MonoPointed IntSet | |
MonoPointed Text | |
MonoPointed Text | |
MonoPointed [a] | |
MonoPointed (Maybe a) | |
MonoPointed (Identity a) | |
MonoPointed (Set a) | |
MonoPointed (Seq a) | |
MonoPointed (DList a) | |
MonoPointed (Option a) | |
MonoPointed (NonEmpty a) | |
Hashable a => MonoPointed (HashSet a) | |
MonoPointed (Vector a) | |
Unbox a => MonoPointed (Vector a) | |
Storable a => MonoPointed (Vector a) | |
MonoPointed (Either a b) | |
MonoPointed mono => MonoPointed (MinLen (Succ Zero) mono) | |
MonoPointed mono => MonoPointed (MinLen Zero mono) |