Git Product home page Git Product logo

curry-functors's Introduction

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

curry-functors's People

Contributors

fwcd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.