Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Last active January 3, 2016 04:19
Show Gist options
  • Save manjuraj/8408219 to your computer and use it in GitHub Desktop.
Save manjuraj/8408219 to your computer and use it in GitHub Desktop.
Simplifying type signatures using higher-kinded types
scala> def f[M[_]](x: M[Int]) = x
f: [M[_]](x: M[Int])M[Int]
scala> val cb = (x: Int) => println(x)
cb: Int => Unit = <function1>
scala> f[Function1](cb)
<console>:11: error: Function1 takes two type parameters, expected: one
f[Function1](cb)
scala> type Callback[T] = Function1[T, Unit]
defined type alias Callback
scala> f[Callback](cb)
res4: Int => Unit = <function1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment