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
Type disambiguation and PPX #10572
Comments
cc @mlasson |
Does the following alternate approach look realistic ? (* Before instrumentation *)
(fun x y : t -> body)
(* With current Landmark *)
(fun x y : t -> let r = body in Landmark.exit (); r)
(* Alternative *)
(fun x y -> let[@local always] orig = (fun x y : t -> body) in let r = orig x y in Landmark.exit (); r) With the local functions optimisation, that should give you the same code in the end, but the type-checker would still see the type annotations in the right place. |
@lthls, yes it does ! I think should be able to use this trick to solve LexiFi/landmarks#31 without any modification to the compiler. |
It looks like currently the typing of Personally I think it would be nice if expert metaprogramming users could control propagation of type information through type variables as proposed by François (using |
I think that using variables like that in a principal way would require a different notion of type variable, with different scoping and behaviour. It's not enough to change the order of unification in constraints -- that will work without How often do people really need to move some user code from a checking position to an inference position? Adding some cleanup code, as in this example, is an obvious case, but that might be better served by just adding a simple |
@lthls it does not always works. The case is simplified, in the real case However it could still be an improvement for landmark in other cases. EDIT: In fact the type variable trick works already! If it is put before the equal at the place of an absent |
And |
@bobot regarding the type variable, |
Indeed, it would be possible to propagate the expected type to the expression, combining it with the type annotation. This must be done with care, so that we really add information. I believe I just assumed that if you give a type annotation it would be precise enough that you don't need to propagate the expected type through it.
As @lpw25 explained, type variables can be used as constraints, but they cannot be used to propagate explicit type information, because the algorithm will always see them as implicit in principal mode. If you want to use local abbreviations, you can do something like this, but I don't know if this is very practical: module M = struct type t = A end
type (_,_) eq = Refl : ('a,'a) eq
let f (type a) (w : (a, M.t) eq) = let Refl = w in (A : a) |
I don't understand your proposed translation. How would you transform let f x : M.t =
let r = A in Landmark.exit (); r to ensure that the expected type of |
To be clear, I wasn't proposing that |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
A PPX could break type disambiguation of constructors in the sense that the code compile before the ppx and not after. For example landmark wrap function in a way comparable to the second version of the function.
The first function types but not the second one because the typer doesn't know that the type of
r
is the type of the whole expression.A ppx could add type variables for simplifying the link to the OCaml typer:
The typer would need to look at the type annotation before typing the term, which it seems not to do currently (surely for a good reason).
The text was updated successfully, but these errors were encountered: