@hackage mono-traversable0.3.0.0
Type classes for mapping, folding, and traversing monomorphic containers
Deprecated
Dependencies (12)
- base >=4.5 && <4.7
- bytestring >=0.9
- comonad >=3.0.3
- containers >=0.4
- hashable
- semigroupoids >=3.0 Show all…
Dependents (106)
@hackage/rfc, @hackage/yesod-csp, @hackage/axel, @hackage/hw-succinct, @cardano/flat, @hackage/ihp, Show all…
mono-traversable
Type classes for mapping, folding, and traversing monomorphic containers. Contains even more experimental code for abstracting containers and sequences.
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
