acme-cofunctor-0.1.1.0: A Cofunctor is a structure from category theory dual to Functor

Safe HaskellSafe
LanguageHaskell98

Data.Cofunctor

Description

Cofunctor is a structure from category theory dual to Functor

A Functor is defined by the operation fmap:

fmap :: (a -> b) -> (f a -> f b)

This means that its dual must be defined by the following operation:

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

Since beginning his investigations, the author of this package has discovered that this pattern is at least as commonly used as Functor. In fact, many ubiquitous Haskell types (e.g. [], Maybe, ((->) a) turn out to have a Cofunctor instance.

Synopsis

Documentation

class Cofunctor f where Source #

Cofunctor is a structure from category theory dual to Functor

Minimal complete definition

cofmap

Methods

cofmap :: (b -> a) -> f b -> f a Source #

Instances

Cofunctor [] Source # 

Methods

cofmap :: (b -> a) -> [b] -> [a] Source #

Cofunctor Maybe Source # 

Methods

cofmap :: (b -> a) -> Maybe b -> Maybe a Source #

Cofunctor IO Source # 

Methods

cofmap :: (b -> a) -> IO b -> IO a Source #

Cofunctor ((->) a) Source # 

Methods

cofmap :: (b -> a) -> (a -> b) -> a -> a Source #

Cofunctor (Either e) Source # 

Methods

cofmap :: (b -> a) -> Either e b -> Either e a Source #

Cofunctor ((,) a) Source # 

Methods

cofmap :: (b -> a) -> (a, b) -> (a, a) Source #

Cofunctor (Cocoyoneda f) Source # 

Methods

cofmap :: (b -> a) -> Cocoyoneda f b -> Cocoyoneda f a Source #