Skip to content

Latest commit

 

History

History

coalgebras

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

You'll find here an implementation of coalgebraic-related type classes and demonstrators. It's the accompanied code to the Cádiz typelevel summit's proposal "We are reative! Programming actor systems through cofree coalgebras". Some slides can be found here.

The coalgebras object package contains common definitions used in the different gists: FinalCoalgebra, CofreeCoalgebra, F-Coalgebra, IO-Coalgebra, etc. The cats and scalaz subpackages contains the following gists (note: cats version under preparation).

Machines

  • automata.scala (scalaz,cats), sample definition of a Moore automaton as an IO-coalgebra, i.e. as an interpretation of an input algebra over a state-based language; it's used throughout the other gists.
  • automatasample.scala (scalaz,cats), sample instantiation of the Moore automaton.

Programming machines

Given the IO language of the automaton, we can implement different kinds of programs over it. The IO language just provides the "instructions" or buttons of the machine, which can be combined as we wish: monadically, applicatively, etc.

  • programmingimperatively.scala (scalaz,cats). Example of imperative programming over Moore automata.
  • programmingapplicatively.scala (scalaz,cats). Sometimes, monadic combinators are not really needed. In that case, we can simply use applicative ones.
  • programmingwithexceptions.scala (scalaz,cats). We can also use pattern matching in for-comprehensions, with the help of the MonadError API.

Universal machines

These are final and cofree coalgebra instantiations of Moore machines.

  • finaladhoc.scala (scalaz,cats), represents the behaviour of Moore automata in terms of the accepted language.
  • cofreecochurch.scala (scalaz,cats), represents the behaviour implicitly, in terms of the Church's dual encoding of greatest fix points.
  • cofreecomonad.scala (scalaz,cats), uses the cofree comonad for F-algebras.
  • cofreeactor.scala (scalaz,cats), uses actors to provide a framework for execution in terms of cofree coalgebras.
  • cofreeweb.scala (scalaz,cats), does the same for a Web-based interface.