Implicit parameters...?

I'd like to be clear that this is not how implicit values work; We can make up some alternative model but this isn't Scala's implicit values -- which are being discussed for inspiration here so I think it matters to not attribute behavior to them which they do not exhibit..

Implicit values must be in the "implicit search scope". This isn't some arbitrary stack search. It must be accessible in scope -- and not just somewhere on the callstack.

The lookups are performed, more or less in the following order (I may get this slightly wrong, it's been a while):

  • current scope (e.g. block or method)
  • explicit imports of implicit values (Scala can import values, import Clazz.value which is how one can import an execution context etc)
  • other imports
  • associated static scope of involved types (e.g. this way a type provides "default implicit value" if search fails)
  • containing type (e.g. an implicit property inside a struct containing the function in which we're trying to call something that needs an implicit)
  • implicit scope of arguments type, ... (e.g. Timeout may have values defined)
  • outer types if the type was nested
  • global scope (another way for defaults)
  • ...

The lookups can get somewhat expensive in very convoluted cases.

2 Likes