Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created July 26, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubukoz/cc4e0f983e39c0daf7650f53ae6ac4bd to your computer and use it in GitHub Desktop.
Save kubukoz/cc4e0f983e39c0daf7650f53ae6ac4bd to your computer and use it in GitHub Desktop.
import shapeless._
def abc0[M[_]] = ???
def abc1[M[+_]] = ???
def abc2[M[-_]] = ???
//this one should accept an arbitrary invariant M
def abc3[M[_] <: Set[_]] = ???
type Predicate[-a] = a => Boolean
//M[_] works for all
abc0[Predicate]
abc0[List]
abc0[Set]
//M[+_] works for covariant types
illTyped("""abc1[Predicate]""")
abc1[List]
illTyped("""abc1[Set]""")
//M[-_] works for contravariant types
abc2[Predicate]
illTyped("""abc2[List]""")
illTyped("""abc2[Set]""")
//this should happen
illTyped("""abc3[List]""")
illTyped("""abc3[Predicate]""")
abc3[Set]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment