ocaml-modular-implicits icon indicating copy to clipboard operation
ocaml-modular-implicits copied to clipboard

Allow rebinding/shadowing of implicits in the top level

Open yallop opened this issue 11 years ago • 3 comments
trafficstars

It'd be useful to allow rebinding/shadowing of implicit modules in the top level:

# implicit module M = struct end;;
implicit module M : sig  end
# implicit module M = struct end;;
implicit module M : sig  end
# module type S = sig end;;
module type S = sig  end
# let f (implicit X : S) () = ();;
val f : (implicit X : S) -> unit -> unit = <fun>
# f ();;
Characters 0-1:
  f ();;
  ^
Error: Ambiguous implicit X: M/1017 and M/1016
are both solutions.

The top level allows rebinding/shadowing of types and modules, even though they need to be unique inside a module. Perhaps we can adopt a similar approach with implicits.

yallop avatar Sep 17 '14 13:09 yallop

I am not sure what the rule would be. In case of ambiguity with syntactically equal paths, ignore and always use the most recent one?

let-def avatar Sep 17 '14 15:09 let-def

That could work, but I think it might be better to exclude all but the most recent instance of each path from the search altogether, even if there's no ambiguity. If shadowing still leaves implicits available for search then you need an additional mechanism for removing erroneous definitions from the top-level environment.

yallop avatar Sep 18 '14 12:09 yallop

Note that Scala allows shadowing implicits like any other method, but it can have a very confusing effect. If you add a definition which name appears nowhere in a working program, it may still break the program if it happens to shadow an implicit the program was using -- even if the new definition is not implicit. This is terrible, because you do not always know the names of all implicits a program is using, and do not realize you are shadowing one.

LPTK avatar Jan 08 '16 17:01 LPTK