'using' available for instances?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

'using' available for instances?

sledorze
Hi!

This email to challenge an idea of a possible usage of a variation of extensions resolution.
Some of you may know I try to find some ways to bring implicits.
Unfortunately, solely relying on macros (and considering not transforming all code) it seems not possible as of today.

So here's the idea:

having the possibility to expose, in a scope, the functions of an instance as if they were some public static functions of a class.

So that one can use the extension resolution which would use the methods of this instance.

Some code:

class MyClass {
  public function myClassMethod(y : Foo, str : String) { ... }
}

function myTestMethod(y : Foo) {
  var x = new MyClass();
  using x;

  y.myClassMethod("42");
}

(((
and for those which followed to call Site macro stuff :

function myTestMethod<T>(y : T, ?tIsShowable : Show<T> = y.getShow()) {
  using tIsShowable;

  y.show(); // usage

  myTestMethod(y); // the point is not about recursion but the transparent type class passing.
}
)))

For me that would just be awesome.
Doing that would enable a lot more implicits usages - like transaction contexts, etc..

I know, there's *not* a majority of people right that use functionnal programming - for which this feature would be a game changer.

And it is clear that this email is also directed to get attention from a certain person,
However, I'm pretty sure you also see other opportunities I would really like to hear about..

Please share if you find it interesting (or not!) :)

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: 'using' available for instances?

sledorze
To clarify; of course;

function myTestMethod(y : Foo) {
  var x = new MyClass();
  using x;

  y.myClassMethod("42");
}

would be compiled to:

function myTestMethod(y : Foo) {
  var x = new MyClass();

  x.myClassMethod(y, "42");
}