Skip to content

Commit

Permalink
Add a note about issues with Functor.widen
Browse files Browse the repository at this point in the history
This is a followup on [this
discussion](typelevel#1080 (comment)).
  • Loading branch information
ceedubs committed Jul 16, 2016
1 parent 4f7b79a commit 2091960
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/scala/cats/Functor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import simulacrum.typeclass

/**
* Lifts natural subtyping covariance of covariant Functors.
* could be implemented as map(identity), but the Functor laws say this is equivalent
*
* NOTE: In certain (perhaps contrived) situations that rely on universal
* equality this can result in a `ClassCastException`, because it is
* implemented as a type cast. It could be implemented as `map(identity)`, but
* according to the functor laws, that should be equal to `fa`, and a type
* cast is often much more performant.
* See [[https://github.com/typelevel/cats/issues/1080#issuecomment-225892635 this example]]
* of `widen` creating a `ClassCastException`.
*/
def widen[A, B >: A](fa: F[A]): F[B] = fa.asInstanceOf[F[B]]

Expand Down

0 comments on commit 2091960

Please sign in to comment.