Skip to content

Instantly share code, notes, and snippets.

@softprops
Created February 20, 2011 05:21
Show Gist options
  • Save softprops/835732 to your computer and use it in GitHub Desktop.
Save softprops/835732 to your computer and use it in GitHub Desktop.
trying to recollect type class teachings of Mark Harrah
trait Builder[M[_], N[_]] {
type Apply[T] = M[N[T]]
}
implicit def optionIntListBuilder: Builder[List, Option]#Apply[Int] = List.empty[Option[Int]]
// make a list of option[T]
def make[T](implicit p: Builder[List, Option]#Apply[T]): List[Option[T]] = p
make[Int] // List[Option[Int]]
make[String] // error: could not find implicit value for parameter p: List[Option[String]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment