HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemono-traversable-1.0.21.0Haskell2010

Data.MonoTraversable

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!)

  • 2 types
  • 6 classes
  • 26 values
familytype family Element mono
#

Type family for getting the type of the elements of a monomorphic container.

Instances59Element, …
  • type Element Builder = Word8Defined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element ByteString = Word8Defined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element ByteString = Word8Defined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element IntSet = IntDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element Text = CharDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element Builder = CharDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element Text = CharDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WrappedArrow a b c) = cDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WrappedMonad m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Compose f g a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Product f g a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Arg a b) = bDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (IntMap a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Map k v) = vDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Seq a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (ViewL a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (ViewR a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Set e) = eDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Tree a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (NonEmpty a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Either a b) = bDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Const m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Identity a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Proxy a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (ZipList a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (K1 i c a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (M1 i c f a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Par1 a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Rec1 f a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (U1 a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (V1 a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Maybe a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (IO a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WrappedMono mono a) = Element monoDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WrappedPoly f a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (NonNull mono) = Element monoDefined in mono-traversable-1.0.21.0 · Data.NonNull
  • type Element (ContT r m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (IdentityT m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (MaybeT m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (RWST r w s m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (RWST r w s m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (ReaderT r m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (StateT s m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (StateT s m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WriterT w m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (WriterT w m a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Reverse f a) = Element (f a)Defined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (HashMap k v) = vDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (HashSet e) = eDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Vector a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Vector a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Vector a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (Vector a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element ((:*:) f g a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element ((:+:) f g a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element ((:.:) f g a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (a, b) = bDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element (r -> a) = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
  • type Element [a] = aDefined in mono-traversable-1.0.21.0 · Data.MonoTraversable
classclass MonoFunctor mono where
#

Monomorphic containers that can be mapped over.

Methods

Instances54MonoFunctor, …
classclass MonoFoldable mono where
#

Monomorphic containers that can be folded.

Methods

Instances45MonoFoldable, …
classclass (MonoFunctor mono, MonoFoldable mono) => MonoTraversable mono where
#

Monomorphic containers that can be traversed from left to right.

NOTE: Due to limitations with the role system, GHC is yet unable to provide newtype-derivation of MonoTraversable. See https://stackoverflow.com/questions/49776924/newtype-deriving-issequence.

Methods

  • otraverse :: Applicative f => (Element mono -> f (Element mono)) -> mono -> f mono

    Map each element of a monomorphic container to an action, evaluate these actions from left to right, and collect the results.

  • omapM :: Applicative m => (Element mono -> m (Element mono)) -> mono -> m mono

    Map each element of a monomorphic container to a monadic action, evaluate these actions from left to right, and collect the results.

Instances40MonoTraversable, …
valueofoldlUnwrap
  1. :: MonoFoldable mono
  2. => x -> Element mono -> x
  3. -> x
  4. -> x -> b
  5. -> mono
  6. -> 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.

valueofoldMUnwrap
  1. :: (Monad m, MonoFoldable mono)
  2. => x -> Element mono -> m x
  3. -> m x
  4. -> x -> m b
  5. -> mono
  6. -> 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.

classclass MonoPointed mono where
#

Typeclass for monomorphic containers that an element can be lifted into.

For any MonoFunctor, the following law holds:

omap f . opoint = opoint . f

Methods

Instances52MonoPointed, …
classclass MonoFunctor mono => MonoComonad mono where
#

Typeclass for monomorphic containers where it is always okay to "extract" a value from with oextract, and where you can extrapolate any "extracting" function to be a function on the whole part with oextend.

oextend and oextract should work together following the laws:

oextend oextract      = id
oextract . oextend f  = f
oextend f . oextend g = oextend (f . oextend g)

As an intuition, oextend f uses f to "build up" a new mono with pieces from the old one received by f.

Methods

  • oextract :: mono -> Element mono

    Extract an element from mono. Can be thought of as a dual concept to opoint.

  • oextend :: (mono -> Element mono) -> mono -> mono

    Extend a mono -> Element mono function to be a mono -> mono; that is, builds a new mono from the old one by using pieces glimpsed from the given function.

Instances3MonoComonad
classclass MonoFoldable mono => GrowingAppend mono
#

Containers which, when two values are combined, the combined length is no less than the larger of the two inputs. In code:

olength (x <> y) >= max (olength x) (olength y)

This class has no methods, and is simply used to assert that this law holds, in order to provide guarantees of correctness (see, for instance, Data.NonNull).

This should have a Semigroup superclass constraint, however, due to Semigroup only recently moving to base, some packages do not provide instances.

Instances18GrowingAppend, …
newtypenewtype WrappedPoly (f :: Type -> Type) a
#

Provides a MonoFoldable, MonoFunctor or MonoPointed for an arbitrary Foldable, Functor or Applicative.

Useful for, e.g., passing a Foldable type you don't own into a function that expects a MonoFoldable.

// package A
data MyList a = MyList [a] deriving Foldable

// package B
process :: MonoFoldable mono => mono -> IO ()

// package C
process (WrappedPoly (MyList []))

Constructors

Instances8Monad, Functor, Applicative, Foldable, MonoFoldable, MonoFunctor, …
datadata WrappedMono mono a where
#

Provides a Foldable for an arbitrary MonoFoldable.

Constructors

Instances5Foldable, MonoFoldable, MonoFunctor, MonoPointed, Element