Created
March 13, 2012 20:49
-
-
Save milessabin/2031481 to your computer and use it in GitHub Desktop.
Impredicative types in Scala via shapeless
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
// 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