# Tag Info

11

There are absolutely some relationships between the semantics and practice of OOP and category theory. This is somewhat unsurprising since both fields attempt to give a principled generic account of structure and behavior in a synthetic manner. The most apparent work I am aware of is the categorical semantics of UML, which is admittedly different from OOP ...

6

Update (2020) Have a look at this year's CPPCon talk - Monoids, Monads, and Applicative Functors: Repeated Software Patterns Also look for mentions of the Fin category in Category Theory in Context Objects can implement category theoretic data types and access patterns. For a better understanding I would recommend Stepanov's book , Mike Stay's article, and ...

5

What you are looking for are called "self types", and have been studied theoretically for ~20 years or so. For example, see Safe Type Checking in a Statically-Typed Object-Oriented Programming Language by Kim B. Bruce, in the 1993 POPL (Principles of Programming Languages), pp. 285-298. Off the top of my head, John Mitchell and Kathleen Fisher have also ...

5

Bart Jacobs tackled this problem at one point. In his view, classes can be considered as coalgebras. Roughly, we have a polynomial endofunctor $F : \mathbf{Sets} \to \mathbf{Sets}$ which gives the class's type signature. A pair of a carrier set $X$ and an arrow $X \to FX$ is then used to "implement" the class. For example, consider a class ...

4

Final Algebra semantics was introduced by Mitch Wand in his paper "Final Algebra Semantics and Data Type Extensions", see this freely available tech report: https://www.cs.indiana.edu/ftp/techreports/TR65.pdf . It does not mean final coalgebra semantics, which is a very different idea. The wrinkle is that the algebra is not final in the same category that ...

4

Perhaps you are looking for modules. For example, the following code uses OCaml's module system to define a signature for monoids and two implementations: module type Monoid = sig type t val identity : t val oper : t -> t -> t end module IntSum : Monoid = struct type t = int let identity = 0 let oper x y = x + y end module IntProd : ...

2

In Scala you can use parametric polymorphism for this, e.g. like so: trait A [ T ] { def f ( t : T ) : T def g ( t : T ) : T = t } class AImpl () extends A [ AImpl ] { def f ( t : AImpl ) : AImpl = t } (Traits are a generalisation of Java interfaces). This can be resolved at compile-time, although I don't know how the Scala compiler and the JVM ...

1

I took a brief look at the first paper you cite, and I think Max New's answer does have some relevance to it. The purpose of this answer is to explain how I think the 'finally tagless' stuff gets a bit confused itself about the idea. The paper starts with a simple algebraic signature for a language with literal numbers, addition and negation. It says that ...

Only top voted, non community-wiki answers of a minimum length are eligible