cofunctor- DEPRECATED: use the "contravariant" package




class Cofunctor f whereSource

DEPRECATED: please use the "contravariant" package

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


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