Skip to content
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

Add implicit statement #28

Open
wants to merge 3 commits into
base: modular-implicits
Choose a base branch
from

Conversation

let-def
Copy link
Contributor

@let-def let-def commented Dec 12, 2014

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:

  • discuss interaction with module inclusion relation
  • rewrite "implicit module X = …" into "module X = … implicit X" directly in the parser? (how would pretty-printing behave? directly matching Tsig_module X :: Tsig_implicit X' :: _ to recover sugared form?
    Also, the parser structure_item and signature_item are expected to produce a single item, though it's not a problem to lift this to a list
  • add similar construction in let-bindings (let implicit X in …)
  • complete and test the implementation

@lpw25
Copy link
Member

lpw25 commented Dec 15, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants