Created
January 10, 2014 20:15
-
-
Save mergeconflict/8361764 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
// this is really "category" but omg math words | |
trait Stackable[S[_, _]] { | |
def compose[A, B, C](lhs: S[A, B], rhs: S[B, C]): S[A, C] | |
def id[A]: S[A, A] | |
} | |
object Stackable { | |
// for example ... | |
implicit val function1stackable = new Stackable[Function1] { | |
def compose[A, B, C](lhs: A => B, rhs: B => C): A => C = lhs andThen rhs | |
def id[A]: A => A = identity | |
} | |
} | |
class Stack[S[_, _], A, B](implicit stackable: Stackable[S]) { | |
val impl = // a heterogeneous collection of S[_, _] elements, where the first elem is S[A, _] and the last is S[_, B] | |
def build: S[A, B] = impl.foldLeft(stackable.id)(stackable.compose) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment