Created
November 13, 2017 10:52
-
-
Save mandubian/284c405fa0f9726017405c731ba34734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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