cofunctor-0.1.0: A small library providing a contravariant functor class

Data.Cofunctor

Synopsis

Documentation

class Cofunctor f whereSource

The Confunctor class is useful for "sink-like" types, especially when combined with GADTs. For instance:

 
 data StringStack a where
     StringStack :: (a -> String) -> [String] -> StringStack a

 emptyStack :: StringStack String
 emptyStack = StringStack id []

 push :: a -> StringStack a -> StringStack a
 push a (StringStack f ss) = StringStack f (f s : ss)

 instance Confunctor StringStack where
     cofmap f (StringStack g ss) = StringStack (g . f) ss

See the split-chan package for another example.

A class for contravariant functors

Methods

cofmap :: (b -> a) -> f a -> f bSource