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

[ data, library, mit ] [ Propose Tags ]

Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. Contains even more experimental code for abstracting containers and sequences.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.3.0.3, 0.3.1, 0.4.0, 0.4.0.1, 0.4.0.2, 0.4.0.3, 0.4.0.4, 0.5.0, 0.6.0, 0.6.0.1, 0.6.0.2, 0.6.0.3, 0.6.0.4, 0.6.1, 0.6.2, 0.6.3, 0.7.0, 0.8.0, 0.8.0.1, 0.9.0, 0.9.0.1, 0.9.0.2, 0.9.1, 0.9.2, 0.9.2.1, 0.9.3, 0.10.0, 0.10.0.1, 0.10.1, 0.10.1.1, 0.10.2, 1.0.0, 1.0.0.1, 1.0.1, 1.0.1.1, 1.0.1.2, 1.0.1.3, 1.0.2, 1.0.2.1, 1.0.4.0, 1.0.5.0, 1.0.6.0, 1.0.7.0, 1.0.8.0, 1.0.8.1, 1.0.9.0, 1.0.10.0, 1.0.11.0, 1.0.12.0, 1.0.13.0, 1.0.15.0, 1.0.15.1, 1.0.15.2, 1.0.15.3, 1.0.17.0 (info)
Dependencies base (>=4.5 && <4.9), bytestring (>=0.9), comonad (>=3.0.3), containers (>=0.4), dlist (>=0.6 && <1.0), dlist-instances (>=0.1 && <0.2), hashable, semigroupoids (>=3.0), semigroups (>=0.10), text (>=0.11), transformers (>=0.3), unordered-containers (>=0.2), vector (>=0.10), vector-algorithms (>=0.6), vector-instances [details]
License MIT
Author Michael Snoyman, John Wiegley, Greg Weber
Maintainer michael@snoyman.com
Revised Revision 2 made by HerbertValerioRiedel at 2016-02-16T08:47:30Z
Category Data
Home page https://github.com/snoyberg/mono-traversable
Source repo head: git clone git://github.com/snoyberg/mono-traversable.git
Uploaded by MichaelSnoyman at 2014-07-10T08:29:52Z
Distributions Arch:1.0.15.3, Debian:1.0.15.1, Fedora:1.0.15.3, FreeBSD:0.9.2.1, LTSHaskell:1.0.17.0, NixOS:1.0.15.3, Stackage:1.0.17.0, openSUSE:1.0.15.3
Reverse Dependencies 87 direct, 4610 indirect [details]
Downloads 122260 total (527 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]

Readme for mono-traversable-0.6.0.4

[back to package description]

mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers. Contains even more experimental code for abstracting containers and sequences.

A polymorphin container is one such as list which has a type variable [a] A monomorphic container is one such as Text which has a type Text that does not expose the underlying characters.

Adding instances

If you have a data type which is a member of one of the relevant typeclasses (Functor, Foldable, Traversable), its quite easy to add an instance for MonoFunctor, MonoFoldable or MonoTraversable.

You just have to declare the proper type instance:

    {-# LANGUAGE TypeFamilies         #-}
    
    (...)
    
    -- type instance Element T.Text = Char  -- already defined
    -- type instance Element [a] = a        -- here for example
    type instance Element (CustomType a) = a

And then, the needed instances:

    instance MonoFunctor (CustomType a)
    instance MonoFoldable (CustomType a)
    instance MonoTraversable (CustomType a)

in your code, and your ready to use CustomType a with the functions defined in this package.

Note: if your type is as monomorphic container without the proper typeclasses, then you will have to provide an implementation. However, this should be fairly simple, as it can be seen in the code

mono-traversable versuse lens Traversal

lens is a huge package with a lot of functionality. One piece of functionality it exposes is Fold and Traversal which can also be used to deal with monomorphic containers.

You could prefer mono-traversable to using this part of lens because

  • There is really no new API to learn. If you know Foldable, you can use MonoFoldable just as easily
  • mono-traversable's typeclass based approach means many methods are included in the class but can easily be given specialised optimized implementations
  • You don't need to explicitly pass around the Traversal

The last point is also a point of inflexibility and points to a use case where you could prefer using a lens Traversal. mono-traversable treats ByteString as a sequence of bytes. If you want to treat it as both bytes and characters, mono-traversable would require a newtype wrapper around ByteString, whereas a lens traversal would just use a different traversal function.

Build Status