Skip to content

Instantly share code, notes, and snippets.

@ryoppy
Created December 14, 2014 22:00
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 ryoppy/2756593ca3e068c6edf6 to your computer and use it in GitHub Desktop.
Save ryoppy/2756593ca3e068c6edf6 to your computer and use it in GitHub Desktop.
scala> def fid[F[_], A](a: F[A]): F[A] = a
warning: there was one feature warning; re-run with -feature for details
fid: [F[_], A](a: F[A])F[A]
scala> fid(List(1))
res0: List[Int] = List(1)
scala> fid(Option(1))
res1: Option[Int] = Some(1)
scala> fid(Right(1))
<console>:9: error: no type parameters for method fid: (a: F[A])F[A] exist so that it can be applied to arguments (scala.util.Right[Nothing,Int])
--- because ---
argument expression's type is not compatible with formal parameter type;
found : scala.util.Right[Nothing,Int]
required: ?F[?A]
fid(Right(1))
^
<console>:9: error: type mismatch;
found : scala.util.Right[Nothing,Int]
required: F[A]
fid(Right(1))
^
scala> type FRight[A] = Either[String, A]
defined type alias FRight
scala> fid[FRight, Int](Right(1))
res4: FRight[Int] = Right(1)
scala> fid[({type F[A] = Either[String, A]})#F, Int](Right(1))
res5: scala.util.Either[String,Int] = Right(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment