• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

coq/H09-Sep-2001-9777

examples/H09-Sep-2001-6243

src/H03-May-2022-1,412686

tests/H09-Sep-2001-2610

.ghciH A D09-Sep-200185 21

.gitignoreH A D09-Sep-2001280 3332

.hlint.yamlH A D09-Sep-2001121 53

.travis.ymlH A D09-Sep-20019.3 KiB184182

.vim.customH A D09-Sep-2001767 3223

CHANGELOG.markdownH A D09-Sep-20012.4 KiB10885

LICENSEH A D09-Sep-20011.3 KiB2822

README.markdownH A D09-Sep-20012 KiB6141

Setup.lhsH A D09-Sep-2001673 3525

Warning.hsH A D09-Sep-2001256 62

comonad.cabalH A D09-Sep-20013.3 KiB134118

README.markdown

1comonad
2=======
3
4[![Hackage](https://img.shields.io/hackage/v/comonad.svg)](https://hackage.haskell.org/package/comonad) [![Build Status](https://secure.travis-ci.org/ekmett/comonad.svg?branch=master)](http://travis-ci.org/ekmett/comonad)
5
6This package provides comonads, the categorical dual of monads. The typeclass
7provides three methods:  `extract`, `duplicate`, and `extend`.
8
9    class Functor w => Comonad w where
10        extract :: w a -> a
11        duplicate :: w a -> w (w a)
12        extend :: (w a -> b) -> w a -> w b
13
14There are two ways to define a comonad:
15
16I. Provide definitions for `extract` and `extend` satisfying these laws:
17
18    extend extract      = id
19    extract . extend f  = f
20    extend f . extend g = extend (f . extend g)
21
22In this case, you may simply set `fmap` = `liftW`.
23
24These laws are directly analogous to the [laws for
25monads](https://wiki.haskell.org/Monad_laws). The comonad laws can
26perhaps be made clearer by viewing them as stating that Cokleisli composition
27must be a) associative and b) have `extract` for a unit:
28
29    f =>= extract   = f
30    extract =>= f   = f
31    (f =>= g) =>= h = f =>= (g =>= h)
32
33II. Alternately, you may choose to provide definitions for `fmap`,
34`extract`, and `duplicate` satisfying these laws:
35
36    extract . duplicate      = id
37    fmap extract . duplicate = id
38    duplicate . duplicate    = fmap duplicate . duplicate
39
40In this case, you may not rely on the ability to define `fmap` in
41terms of `liftW`.
42
43You may, of course, choose to define both `duplicate` _and_ `extend`.
44In that case, you must also satisfy these laws:
45
46    extend f  = fmap f . duplicate
47    duplicate = extend id
48    fmap f    = extend (f . extract)
49
50These implementations are the default definitions of `extend` and`duplicate` and
51the definition of `liftW` respectively.
52
53Contact Information
54-------------------
55
56Contributions and bug reports are welcome!
57
58Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.
59
60-Edward Kmett
61