New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading comment on private type abbreviations #6548
Comments
Comment author: @lpw25
This sentence should indeed be removed, but not for the reason suggested. It should be removed because this limitation was removed in version 4.02:
This exhaustivity check is not failing because
Then the exhaustivity check passes as you wanted. Also note that with a regular private type abbreviation you cannot match directly on the abbreviated type, but must instead use a coercion:
So it is actually private type abbreviations that are more restricted than private row types. |
Comment author: pveber Thanks a lot Leo for this explanation. It solves my initial problem well: I'll indeed use a private row type, but a closed one. Also I'm glad I found a bug in the documentation, even if for a totally wrong reason ;o). |
Comment author: @Octachron The obsolete remark on the limitations of private type abbreviations was removed from the manual by integrating #1165 . |
Original bug ID: 6548
Reporter: pveber
Assigned to: @Octachron
Status: resolved (set by @Octachron on 2017-05-08T21:24:18Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.0+beta1 / +rc1
Fixed in version: 4.06.0 +dev/beta1/beta2/rc1
Category: documentation
Tags: junior_job
Related to: #6589
Bug description
In "Language extensions", paragraph 7.9.2 says that
"For ambiguity reasons, typexpr cannot be an object or polymorphic variant type, but a similar behaviour can be obtained through private row types."
Actually private row types behave in a different way than what would be expected from private type abbreviation of a polymorphic variant:
module T
: sig type t = private [>
a |
b] end= struct type t = [
a |
b] end;;
module T : sig type t = private [>
a |
b ] endlet f (x : T.t) = match x with |
a -> true |
b -> false;;Characters 18-57:
Warning 8: this pattern-matching is not exhaustive. Here is an example of a value that is not matched:
`AnyExtraTag
val f : T.t -> bool =
That is, exhaustivity check is not possible any more with private row types. The limitation of this workaround should be indicated, and other workarounds could be suggested:
module T
: sig type t = private u and u = [
a |
b] end= struct type t = [
a |
b] and u = t end;;module T
: sig type t val repr : t -> [
a |
b] end= struct type t = [
a |
b] let repr x = x end;;
The text was updated successfully, but these errors were encountered: