-
Notifications
You must be signed in to change notification settings - Fork 23
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
Polymorphic parameters #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great change, and the code broadly makes sense to me. That said, I think the larger-scale changed structure needs to be clarified. My understanding is that this PR introduces a new invariant that Tarrow
s always start with a Tpoly
. This needs to be called out somehow in the code, and I can see two ways:
-
This could be reflected structurally in the code, such as by adding a new type:
and type_desc = (* ... *) | Tarrow of arrow_desc * type_arg * type_expr * commutable (* ... *) and type_arg = { arg_vars : type_expr list ; arg_type : type_expr } (** [{arg_vars = [a; b]; arg_type = t}] ==> ['a 'b. t]to arrow types Like [Tpoly], but mandatory for arguments *) (* ... *)
(Equivalently,
type_arg
could be inlined into theTarrow
constructor. And maybe it should be flipped around to matchTpoly
.) -
This could be left as an invariant, but documented, and possibly tagged with a type synonym:
and type_desc = (* ... *) | Tarrow of arrow_desc * type_arg * type_expr * commutable (* ... *) and type_arg = type_expr (** A [type_arg] is a [type_expr] that is headed by a [Tpoly] constructor, as is required for the arguments to [Tarrow]s. This isn't checked, but functions that consume [type_arg]s are entitled to assume that it's true. *) (* ... *)
The important thing is that this invariant needs to be legible from the source code; as it stands, it has to be deduced from usage. The tradeoffs between (1) and (2) are fairly typical: on the one hand, if it's reflected structurally, things can't go wrong; on the other hand, then you lose out on having actual type_desc
s/type_expr
s that are Tpoly
s around, which is potentially inconvenient. I can see arguments for both approaches, so I don't have a strong opinion about which approach to take.
On a related explanatory note, it would be good to see some user-facing documentation for this change (and I'd appreciate some clarification on the principality check, although I'm not sure how important that actually is). And upstream will ask for a changelog entry when we bring this to them; is there a reason not to just write one now?
737de59
to
68ceb6a
Compare
I know this is an annoying comment, but it would be really helpful (I think, to all of us, not just newbie me) to have a design document describing this change. That is, this patch is an implementation. But what is the specification of that implementation? Without a specification, it's hard to assess the correctness of an implementation. That is, I can try to read this and figure out whether we've introduced new soundness bugs (clearly bad), but it would be nice if I could do more than just that -- by assessing whether this implementation correctly, optimally implements a specification. Important bonus of having a specification: we then have a document to describe to others (e.g. upstream) what we are up to -- very valuable! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't really gotten to the code proper yet -- still trying to understand the specification as hinted at in the poly_params.ml file. But there's enough to plumb there! More to come, but I thought getting these preliminary thoughts out there might be helpful, in case I time out later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had one place I'd like an extra comment, but this looks good to me :-)
I think that this PR just needs a couple of changes now:
I think the user documentation plus the typing rules should hopefully be a sufficient spec for the feature. |
Yes, I agree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gaining steam understanding the code. More soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I'm timing out here. But this has been really educational for me!
I do hope the "please comment this more" comments are not too annoying. It's very hard as a current outsider to know what the right level is for documentation, but my (very pleasant) experience in working in a heavily commented compiler suggests that more would be better.
71397d0
to
e2a694a
Compare
This is rebased on 4.14 and should be ready to merge once CI has run |
Seems self-explanatory