Skip to content

Instantly share code, notes, and snippets.

@kareblak
Last active December 25, 2015 12:09
Show Gist options
  • Save kareblak/6974587 to your computer and use it in GitHub Desktop.
Save kareblak/6974587 to your computer and use it in GitHub Desktop.
Why?
scala> case class Pair[A,B](head: A, tail: B)

defined class Pair


scala> type HeadlessPair[B] = Pair[Any, B] // Setting it to any, so the compiler wont care when type view is accessed

defined type alias HeadlessPair
scala> def f[A[_], B](ab: A[B]) {}

warning: there were 1 feature warning(s); re-run with -feature for details

f: [A[_], B](ab: A[B])Unit


scala> val headless: HeadlessPair[String] = Pair("begone", "tail")

headless: HeadlessPair[String] = Pair(begone,tail)
scala> f(headless)
<console>:13: error: no type parameters for method f: (ab: A[B])Unit exist so that it can be applied to arguments (Pair[_$1,String])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Pair[_$1,String] where type _$1
required: ?A
f(headless)
^
<console>:13: error: type mismatch;
found : Pair[_$1,String] where type _$1
required: A[B]
f(headless)
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment