ocamllabs / ocaml-modular-implicits

OCaml extended with modular implicits
Other
103 stars 8 forks source link

Add implicit statement #28

Open let-def opened 9 years ago

let-def commented 9 years ago

This patch is incomplete, I just open the pull request to start discussions. It introduces a new item, in signature and structures:

implicit Some.Module
implicit Some.Functor(_)

such that:

implicit module X = EXPR
implicit functor F (A : T) = EXPR

is equivalent to:

module X = EXPR
implicit X

module F (A : T) = EXPR
implicit F(_)

This way it is possible to manage implicits outside of the defining module, and to bind external modules as implicits (e.g implicit Core.Std.Option).

TODO:

lpw25 commented 9 years ago

discuss interaction with module inclusion relation

I think that the best way to think of these is as a set of module paths. This means signature inclusion can just correspond to set inclusion. In other words, an implicit path in the new signature is valid if there is some implicit path in the old signature that is equal to it.

An interesting question is whether to include module aliases (or path normalization in general) in this equality. This would mean that more than one implicit path in the output signature may correspond to a single implicit path in the input signature, but that seems fine (or even useful) to me.

I think it might be also be good idea for Typemod.simplify_sig to remove multiple implicit paths which are syntactically equal (not including module aliases in this equality, since which path is used matters if the alias becomes hidden).

rewrite "implicit module X = …" into "module X = … implicit X" directly in the parser?

Personally, I dislike this kind of syntactic sugar: I think the typedtree should be an accurate reflection of what was in the program. So I would rather see the implicit module form kept as part of the regular module form.

add similar construction in let-bindings (let implicit X in …)

This is not strictly necessery, since let implicit module FreshName = X in would do the same job. But I think it would be a convenient syntax, and should be included for consistency.