Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created November 13, 2017 10:52
Show Gist options
  • Save mandubian/284c405fa0f9726017405c731ba34734 to your computer and use it in GitHub Desktop.
Save mandubian/284c405fa0f9726017405c731ba34734 to your computer and use it in GitHub Desktop.
// A port is just identified by an Int
type Port = Int
// A component has a name and input/ouput ports
final case class Comp[A, B](name: String, inputs: Ports[A], outputs: Ports[B])
// the state monad building the list of components Comp
type GraphM[A] = ((Port, List[Comp[_, _]])) => ((Port, List[Comp[_, _]]), A)
// the kleisli-like directed graph structure based on state monoad
final case class Graph[A, B](f: Ports[A] => GraphM[Ports[B]])
// For info, the different type of ports
sealed trait Ports[A]
case object UnitP extends Ports[Unit]
final case class BooleanP(port: Port) extends Ports[Boolean]
final case class IntP(port: Port) extends Ports[Int]
final case class DoubleP(port: Port) extends Ports[Double]
final case class PairP[A, B](l: Ports[A], r: Ports[B]) extends Ports[(A, B)]
final case class FunP[A, B](f: Graph[A, B]) extends Ports[A :=> B]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment