Skip to content

Contravariant functors, bifunctors, profunctors and more for Curry

License

Notifications You must be signed in to change notification settings

fwcd/curry-functors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Functors for Curry

This package adds a range of more or less exotic functors to Curry, including contravariant functors, bifunctors and profunctors.

Contravariant functors

Contravariant functors, as known from Haskell, are functors that 'flip' the direction of the mapped function:

class Contravariant f where
  contramap :: (a -> b) -> f b -> f a

A simple example of a bifunctor is a regular function where the functor maps over the argument rather than the result.

Bifunctors

Bifunctors, as known from Haskell, are (covariant) functors over types with two arguments:

class Bifunctor p where
  -- | Maps over both arguments at the same time.
  bimap :: (a -> b) -> (c -> d) -> p a c -> p b d

Examples of bifunctors are Either and (,) (2-ary tuples).

Profunctors

Profunctors, as known from Haskell, are functors over types with two arguments where the first argument is contravariant and the second argument is covariant (compare this to bifunctors where both arguments are covariant):

class Profunctor p where
  -- | Maps over both arguments at the same time.
  dimap :: (a -> b) -> (c -> d) -> p b c -> p a d

An example of a profunctor is (->) (functions).

Comonads

Comonads, as known from Haskell, are the dual of monads, i.e. monads construct and comonads deconstruct:

class Functor w => Comonad w where
  extract :: w a -> a
  duplicate :: w a -> w (w a)

Credits

The modules are adapted from BSD-licensed code from Haskell's base libraries and related packages (bifunctors, profunctors, comonad) under the following copyrights:

Module Copyright
Control.Comonad (C) 2008-2015 Edward Kmett, (C) 2004 Dave Menendez
Data.Bifunctor (C) 2008-2014 Edward Kmett
Data.Biapplicative (C) 2011-2015 Edward Kmett
Data.Functor.Compose (c) Ross Paterson 2010
Data.Functor.Const Conor McBride and Ross Paterson 2005
Data.Functor.Contravariant (C) 2007-2015 Edward Kmett
Data.Functor.Sum (c) Ross Paterson 2014
Data.Functor.Product (c) Ross Paterson 2010
Data.Profunctor (C) 2011-2018 Edward Kmett

About

Contravariant functors, bifunctors, profunctors and more for Curry

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages