Skip to content

Instantly share code, notes, and snippets.

@paulp
Created March 17, 2018 23:00
Show Gist options
  • Select an option

  • Save paulp/5a108c6dfb00931bce7fae784fa0e158 to your computer and use it in GitHub Desktop.

Select an option

Save paulp/5a108c6dfb00931bce7fae784fa0e158 to your computer and use it in GitHub Desktop.

Revisions

  1. paulp created this gist Mar 17, 2018.
    26 changes: 26 additions & 0 deletions types.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    object ttypes {
    type ->[+A, +B] = (A, B)
    type PairOf[+A] = A -> A
    type SumOf[+A] = A \/ A

    trait Interpret[T[_[_]]] {
    type ^[Outer[_], Inner[_]] = Outer[T[Inner]]

    trait Transform[F[_], G[_]] {
    type FTF = F[T[F]]
    type GTG = G[T[G]]

    /** Bottom-up transforms. */
    type GAlgebraicM[W[_], M[_]] = F[W ^ G] => M[G ^ G]
    type AlgebraicM[M[_]] = F ^ G => M[G ^ G] // GAlgebraicM[Id, M]
    type GAlgebraic[W[_]] = F[W ^ G] => G ^ G // GAlgebraicM[W, Id]
    type Algebraic = F ^ G => G ^ G // GAlgebraicM[Id, Id]

    /** Top-down transforms. */
    type GCoalgebraicM[N[_], M[_]] = F ^ F => M[G[N ^ F]]
    type CoalgebraicM[M[_]] = F ^ F => M[G ^ F ] // GCoalgebraicM[Id, M]
    type GCoalgebraic[N[_]] = F ^ F => G[N ^ F] // GCoalgebraicM[N, Id]
    type Coalgebraic = F ^ F => G ^ F // GCoalgebraicM[Id, Id]
    }
    }
    }