Questions tagged [category-theory]

Category theory is a branch of abstract mathematics concerned with exposing and describing the underlying structure of logical and mathematical systems. Concepts from category theory have proven to be extremely effective as tools for structuring both the semantics of programming languages and programs themselves. Various category theoretic structures are used as tools for abstraction in programming, including functors, monads, and algebras.

Category theory is a branch of abstract mathematics concerned with exposing and describing the underlying structure of logical and mathematical systems. Concepts from category theory have proven to be extremely effective as tools for structuring both the semantics of programming languages and programs themselves. For example, the category theoretic concept of a monad is now pervasive in functional programming. The seminal work of Moggi in the late 1980s showed that effectful notions of computation (such as state, input/output, exceptions) are captured by the concept of a monad. Wadler showed that monads can be used directly in programming as a tool for abstraction. Now various category theoretic structures are used as tools for abstraction in programming, including functors, monads, comonads, applicative functors (monoidal functors), Kan extensions, adjunctions, algebras, coalgebras, monoids, groups, etc. Such techniques are particular popular in the Haskell programming language.

387 questions
787
votes
5 answers

A monad is just a monoid in the category of endofunctors, what's the problem?

Who first said the following? A monad is just a monoid in the category of endofunctors, what's the problem? And on a less important note, is this true and if so could you give an explanation (hopefully one that can be understood by someone who…
Roman A. Taycher
  • 16,401
  • 19
  • 81
  • 129
386
votes
7 answers

What are free monads?

I've seen the term Free Monad pop up every now and then for some time, but everyone just seems to use/discuss them without giving an explanation of what they are. So: what are free monads? (I'd say I'm familiar with monads and the Haskell basics,…
David
  • 7,728
  • 4
  • 24
  • 32
345
votes
4 answers

What does "coalgebra" mean in the context of programming?

I have heard the term "coalgebras" several times in functional programming and PLT circles, especially when the discussion is about objects, comonads, lenses, and such. Googling this term gives pages that give mathematical description of these…
160
votes
2 answers

Real-world applications of zygohistomorphic prepromorphisms

Yes, these ones: {-#LANGUAGE TypeOperators, RankNTypes #-} import Control.Morphism.Zygo import Control.Morphism.Prepro import Control.Morphism.Histo import Control.Functor.Algebra import Control.Functor.Extras import Control.Functor.Fix import…
barsoap
  • 3,326
  • 3
  • 21
  • 21
79
votes
5 answers

Monads as adjunctions

I've been reading about monads in category theory. One definition of monads uses a pair of adjoint functors. A monad is defined by a round-trip using those functors. Apparently adjunctions are very important in category theory, but I haven't seen…
Bartosz Milewski
  • 9,181
  • 4
  • 34
  • 45
68
votes
4 answers

Is there a monad that doesn't have a corresponding monad transformer (except IO)?

So far, every monad (that can be represented as a data type) that I have encountered had a corresponding monad transformer, or could have one. Is there such a monad that can't have one? Or do all monads have a corresponding transformer? By a…
Petr
  • 60,177
  • 8
  • 136
  • 295
67
votes
4 answers

What is monoid homomorphism exactly?

I've read about monoid homomorphism from Monoid Morphisms, Products, and Coproducts and could not understand 100%. The author says (emphasis original): The length function maps from String to Int while preserving the monoid structure. Such a…
softshipper
  • 26,415
  • 36
  • 123
  • 260
50
votes
8 answers

What is a monad in FP, in categorical terms?

Every time someone promises to "explain monads", my interest is piqued, only to be replaced by frustration when the alleged "explanation" is a long list of examples terminated by some off-hand remark that the "mathematical theory" behind the…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
50
votes
2 answers

Simple examples to illustrate Category, Monoid and Monad?

I am getting very confused with these three concepts. Is there any simple examples to illustrate the differences between Category, Monoid and Monad ? It would be very helpful if there is a illustration of these abstract concepts.
Znatz
  • 1,512
  • 2
  • 18
  • 28
38
votes
2 answers

Does the free monad always exist?

We know from the category theory that not all endofunctors in Set admit a free monad. The canonical counterexample is the powerset functor. But Haskell can turn any functor into a free monad. data Free f a = Pure a | Free (f (Free f a)) instance…
n. 'pronouns' m.
  • 95,181
  • 13
  • 111
  • 206
37
votes
3 answers

What are the adjoint functor pairs corresponding to common monads in Haskell?

In category theory, a monad can be constructed from two adjoint functors. In particular, if C and D are categories and F : C --> D and G : D --> C are adjoint functors, in the sense that there is a bijection hom(FX,Y) = hom(X,GY) for each X in C…
Chris Taylor
  • 44,831
  • 12
  • 101
  • 146
36
votes
3 answers

Arrows are exactly equivalent to applicative functors?

According to the famous paper Idioms are oblivious, arrows are meticulous, monads are promiscuous, the expressive power of arrows (without any additional typeclasses) should be somewhere strictly between applicative functors and monads: monads are…
Cactus
  • 25,576
  • 9
  • 60
  • 130
36
votes
4 answers

What does a nontrivial comonoid look like?

Comonoids are mentioned, for example, in Haskell's distributive library docs: Due to the lack of non-trivial comonoids in Haskell, we can restrict ourselves to requiring a Functor rather than some Coapplicative class. After a little searching I…
betaveros
  • 1,099
  • 9
  • 21
36
votes
2 answers

Difference between free monads and fixpoints of functors?

I was reading http://www.haskellforall.com/2013/06/from-zero-to-cooperative-threads-in-33.html where an abstract syntax tree is derived as the free monad of a functor representing a set of instructions. I noticed that the free monad Free is not much…
Daniel
  • 24,697
  • 12
  • 57
  • 88
36
votes
2 answers

Do Hask or Agda have equalisers?

I was somewhat undecided as to whether this was a math.SE question or an SO one, but I suspect that mathematicians in general are fairly unlikely to know or care much about this category in particular, whereas Haskell programmers might well do. So,…
Ben Millwood
  • 6,450
  • 21
  • 44
1
2 3
25 26