Open union (Scala 2)

    trait in[A, B] {
      def inj(a: A): B
    }
    object in {
      implicit def inSelf[A]: (A in A) = (a: A) => a
      implicit def inHead[A, B]: (A in (A Either B)) = (a: A) => Left(a)
      implicit def inRight[A, B, C](implicit r: (A in C)): (A in (B Either C)) =
        (a: A) => Right(r.inj(a))
      implicit def inLeft[A, B, C](implicit r: (A in B)): (A in (B Either C)) =
        (a: A) => Left(r.inj(a))
    }
Collapse )

Effect Handlers in Scope

http://www.cs.ox.ac.uk/people/nicolas.wu/papers/Scope.pdf

Algebraic effect handlers are a powerful means for describing effectful computations. They provide a lightweight and orthogonal technique to define and compose the syntax and semantics of different effects. The semantics is captured by handlers, which are functions that transform syntax trees. Unfortunately, the approach does not support syntax for scoping constructs, which arise in a number of scenarios. While handlers can be used to provide a limited form of scope, we demonstrate that this approach constrains the possible interactions of effects and rules out some desired semantics.This paper presents two different ways to capture scoped constructs in syntax, and shows how to achieve different semantics by reordering handlers. The first approach expresses scopes using the existing algebraic handlers framework, but has some limitations. The problem is fully solved in the second approach where we introduce higher-order syntax

Categorifying Computations into Componentsvia Arrows as Profunctors

http://group-mmm.org/~ichiro/papers/fromComptoComp.pdf

The notion of arrow by Hughes is an axiomatization of the algebraic structure possessed by structured computations in general. We claim that an arrow also serves as a basic component calculus for composing state-based systems as components—in fact, it is a categorified version of arrow that does so. In this paper, following the second author’s previous work with Heunen, Jacobs and Sokolova,we prove that a certain coalgebraic modeling of components—which generalizes Barbosa’s—indeed carries such arrow structure. Our coalgebraic modeling of components is parametrized by an arrow A that specifies computational structure exhibited by components; it turns out that it is this arrow structure of A that is lifted and realizes the (categorified) arrow structure on components. The lifting is described using the first author’s recent characterization of an arrow as an internal strong monad in Prof, the bicategory of small categories and profunctors