Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created March 13, 2012 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milessabin/2031481 to your computer and use it in GitHub Desktop.
Save milessabin/2031481 to your computer and use it in GitHub Desktop.
Impredicative types in Scala via shapeless
// See http://research.microsoft.com/en-us/um/people/simonpj/papers/boxy/boxy-icfp.pdf
object Impredicative extends App {
import shapeless._
import TypeOperators._
object head extends (List ~> Id) {
def default[T](l : List[T]) = l.head
}
def g(o : Option[List ~> Id]) = o match {
case None => (0, '0')
case Some(get) => (get(List(1, 2)), get(List('a', 'b', 'c')))
}
val gNone = g(None)
assert(gNone == (0, '0'))
val gSome = g(Option(head))
assert(gSome == (1, 'a'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment