Traversable is:module

Class of data structures that can be traversed from left to right, performing an action on each element. Instances are expected to satisfy the listed laws.
If you have a Traversable instance of a record, you can load and store all elements, that are accessible by Traversable methods. We treat the record like an array, that is we assume, that all elements have the same size and alignment. Example:
import Foreign.Storable.Traversable as Store

data Stereo a = Stereo {left, right :: a}

instance Functor Stereo where
fmap = Trav.fmapDefault

instance Foldable Stereo where
foldMap = Trav.foldMapDefault

instance Traversable Stereo where
sequenceA ~(Stereo l r) = liftA2 Stereo l r

instance (Storable a) => Storable (Stereo a) where
sizeOf = Store.sizeOf
alignment = Store.alignment
peek = Store.peek (error "instance Traversable Stereo is lazy, so we do not provide a real value here")
poke = Store.poke
You would certainly not define the Traversable and according instances just for the implementation of the Storable instance, but there are usually similar applications where the Traversable instance is useful.
Generic implementation of Foldable and Traversable. There is already a naive implementation using the generic Rep's own instances of Foldable and Traversable. However, deriving then generates a lot of code that may not be simplified away by GHC, that results in unnecessary run-time overhead. In contrast, this implementation guarantees that the generated code is identical to stock-derived instances of Foldable and Traversable, which have the following syntactic properties:
  • constructors with zero fields use pure once;
  • constructors with one field use fmap once;
  • constructors with n >= 2 fields use liftA2 once and (<*>) n-2 times.
The heavy lifting is actually done by the ap-normalize library.
Class of data structures that can be traversed from left to right, performing an action on each element. Instances are expected to satisfy the listed laws.
All of the functions below work only on «interesting» subterms. It is up to the instance writer to decide which subterms are interesting and which subterms should count as immediate. This can also depend on the context c. The context, denoted c, is a constraint (of kind * -> Constraint) that provides additional facilities to work with the data. In most cases, the context cannot be inferred automatically. You need to provide it using the type application syntax:
gmap @Show f x
everywhere @Typeable f x
etc. For more information, see:
A Foldable instance for functions, given the input is Finite, and a Traversable instance for functions, given the input is Ord and Finite.
This module declares classes for working with structures that accept a single parametric type parameter.
This module declares classes for working with structures that accept a parametric type parameter followed by some fixed kind.
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!)
This module defines higher-order traversable functors.
Provides a "higher-order" version of Traversable and Traversable1, in the same way that HFunctor is a higher-order version of Functor. Note that in theory we could have HFoldable as well, in the hierarchy, to represent something that does not have an HFunctor instance. But it is not clear exactly why it would be useful as an abstraction. This may be added in the future if use cases pop up. For the most part, the things you would want to do with an HFoldable, you could do with hfoldMap or iget; it could in theory be useful for things without HTraversable or Interpret instances, but it isn't clear what those instances might be. For instances of Interpret, there is some overlap with the functionality of iget, icollect, and icollect1.