GithubHelp home page GithubHelp logo

bgamari / comonad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ekmett/comonad

0.0 3.0 0.0 171 KB

Haskell 98 comonads

Home Page: http://hackage.haskell.org/package/comonad

License: Other

Haskell 93.46% Coq 5.06% Shell 1.48%

comonad's Introduction

comonad

Hackage Build Status

This package provides comonads, the categorical dual of monads. The typeclass provides three methods: extract, duplicate, and extend.

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

There are two ways to define a comonad:

I. Provide definitions for extract and extend satisfying these laws:

extend extract      = id
extract . extend f  = f
extend f . extend g = extend (f . extend g)

In this case, you may simply set fmap = liftW.

These laws are directly analogous to the laws for monads. The comonad laws can perhaps be made clearer by viewing them as stating that Cokleisli composition must be a) associative and b) have extract for a unit:

f =>= extract   = f
extract =>= f   = f
(f =>= g) =>= h = f =>= (g =>= h)

II. Alternately, you may choose to provide definitions for fmap, extract, and duplicate satisfying these laws:

extract . duplicate      = id
fmap extract . duplicate = id
duplicate . duplicate    = fmap duplicate . duplicate

In this case, you may not rely on the ability to define fmap in terms of liftW.

You may, of course, choose to define both duplicate /and/ extend. In that case, you must also satisfy these laws:

extend f  = fmap f . duplicate
duplicate = extend id
fmap f    = extend (f . extract)

These implementations are the default definitions of extend andduplicate and the definition of liftW respectively.

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.

-Edward Kmett

comonad's People

Contributors

ekmett avatar r-morgan avatar glguy avatar ggreif avatar ryanglscott avatar arkeet avatar bgamari avatar int-e avatar cartazio avatar quchen avatar fumieval avatar hvr avatar jcristovao avatar supki avatar sjoerdvisscher avatar tonymorris avatar

Watchers

James Cloos avatar  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.