Skip to content

Instantly share code, notes, and snippets.

@undetected1
Created November 1, 2011 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save undetected1/1329769 to your computer and use it in GitHub Desktop.
Save undetected1/1329769 to your computer and use it in GitHub Desktop.
Higher-Kinded types test
package com.sample.higher_kinded
trait Container[M[_]] {
def put[A](x: A): M[A]
def get[A](m: M[A]): A
}
package com.sample.higher_kinded
object HigherKindedTest {
implicit val listContainer = new Container[List] {
def put[A](x: A) = List(x)
def get[A](m: List[A]) = m.head
}
implicit val optionContainet = new Container[Some] {
def put[A](x: A) = Some(x)
def get[A](m: Some[A]) = m.get
}
def tupleize[M[_]: Container, A, B](fst: M[A], snd: M[B]) = {
val c = implicitly[Container[M]]
c.put(c.get(fst), c.get(snd))
}
def main(argc: Array[String]) = {
tupleize(Some(1), Some(2)) foreach println
tupleize(List(1), List(2)) foreach println
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment