Skip to content

Add Contraversable #70

Description

@masaeedu

Hello there. I find it very nice to have an analog for Applicative for Contravariant functors. But it feels like something is missing; where are our nice Traversables?

It seems like there is room for a typeclass like this:

class Functor t => Contraversable t
  where
  {-# MINIMAL contraverse | consequence #-}
  contraverse :: Decidable f => (a -> f b) -> t a -> f (t b)
  consequence :: Decidable f => t (f a) -> f (t b)

A simple application is to note that finite products (e.g. Vec n) are Contraversable. Thus the consequence of a container-ful of Predicates conditions :: Vec n (Predicate a) is consequence conditions :: Predicate (Vec n a), a predicate that gives the conjunction of the result of each predicate in conditions. Similarly, a finite productful of flipped folds can be consequenced to a flipped fold over the product. etc. etc.

Would you be open to a PR that adds this typeclass?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions