You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is much confusion about PartialFunction vs Function1, and I believe this is caused by lack of documentation. Specifically, the following mail from Martin Odersky is not reflected in Function1/PartialFunction ScalaDocs, as of 2.9.1: http://article.gmane.org/gmane.comp.lang.scala.internals/2057
Specifically, Function1 ScalaDocs should explain that the domain is not specified, while PartialFunction ScalaDocs should explain that the domain is now specified, and should clarify (once and for all) whether PartialFunction.apply is allowed to throw exceptions on the domain. In particular, I believe that it should be allowed, otherwise the following code should become illegal:
val f: PartialFunction[Int, Any] = { case _ => 1/0 }
(it compiles on Scala 2.9.1 REPL).
Aaron Novstrup* suggested that whenever PartialFunction.apply throws an exception, that exception must be "part of the design of the function (and should be documented)", which makes sense.
@Blaisorblade said:
Thanks for the prompt response! I added a comment about the wording on the pull request itself, since there I can specify it inline.
@Blaisorblade said:
I noticed that the wording problem also affects the Scala Language Reference (as in release 2.9.1), which in Sec 12.3.3 "The Function Classes" says that "A subclass of Function1 represents partial functions, which are undefined on some points in their domain."
The pull request was merged; after also fixing the language reference (if it is still a problem), this bug could be closed.
There is much confusion about PartialFunction vs Function1, and I believe this is caused by lack of documentation. Specifically, the following mail from Martin Odersky is not reflected in Function1/PartialFunction ScalaDocs, as of 2.9.1:
http://article.gmane.org/gmane.comp.lang.scala.internals/2057
Specifically, Function1 ScalaDocs should explain that the domain is not specified, while PartialFunction ScalaDocs should explain that the domain is now specified, and should clarify (once and for all) whether PartialFunction.apply is allowed to throw exceptions on the domain. In particular, I believe that it should be allowed, otherwise the following code should become illegal:
val f: PartialFunction[Int, Any] = { case _ => 1/0 }
(it compiles on Scala 2.9.1 REPL).
Aaron Novstrup* suggested that whenever PartialFunction.apply throws an exception, that exception must be "part of the design of the function (and should be documented)", which makes sense.
http://stackoverflow.com/a/6836016/53974
The text was updated successfully, but these errors were encountered: