Specifying call site code from a function..

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

Specifying call site code from a function..

sledorze
Hi!

On my road towards bringing type classes to haxe, I stumbled on the fact that it is not possible without inspecting callsite information.

So I was thinking about a feature:

inline public static function foo<T>(x : T, ?y : Show<T> = x.getShow() ) {
...
}

when called with this:

  foo(myDataStructure); // second parameter not specified

would be equivalent to :

   foo(myDataStructure, myDataStructure.getShow());

from that; I think we could bring typeclasses without specifying their instances explicitely ..

What do you think? Do you see other reasons why callsite code insertion would be useful?
(I think the restriction it would applies only to inlinable methods would be fine)

I would really like to hear about it ..
Stéphane
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
You to restate things clearly; getShow would be called within the call site context, not the inner function one.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Juraj Kirchheim
To be honest, I don't quite understand what you're aiming for. Could
you maybe give us a minimal real-life-ish problem and explain how it's
better solved with the approach you're envisaging?

On Sun, Oct 23, 2011 at 3:14 PM, sledorze <[hidden email]> wrote:

> You to restate things clearly; getShow would be called within the call site
> context, not the inner function one.
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6921988.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
Are you asking about type classes or the way I want to bring them in scope?

Type classes are an abstraction mechanism in FP and plays a similar role as classes in OOP.

Their strength is that it gives one the possibility to write some algorithms using some type classes and then whoever wants to use it with some other data can do it (ever if he cannot modify their definition).

There's like hundreds or thousands topics on type classes out there a google from you.


My aim would be to make that usable as in Scala, using implicits.
Maybe this one could be a good start:
http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Juraj Kirchheim
I am somewhat familiar with the concept of type classes as present in Haskell.
However I am not sure of their benefits in a language that supports
both structural and nominal subtyping for objects and allows for
extension through using.

That's why I asked whether there's a class of problems, where using
type classes is an advantage. The problem presented in the blog post
you mentioned really doesn't seem convincing. I mean, the way I see
it, the problem here is printing an Address as a label. Given an
Address and and a print function, I would convert the Address to a
String and the print it. And if that conversion was necessary in
multiple places, I'd put it in a static helper class, that can easily
be used with using. If "printing an address" was needed in more that
one place, then I would define a function for that. This is both clear
and short, without anything implicit - implicitness may seem cool as
you write, but when you read, it's a different beast.

But of course there might be something I am missing. I think it would
be easiest if you maybe had a piece of haXe code that seems overly
clumsy to you and show to what you would like to reduce it, given the
means you are asking for.

On Sun, Oct 23, 2011 at 8:07 PM, sledorze <[hidden email]> wrote:

> Are you asking about type classes or the way I want to bring them in scope?
>
> Type classes are an abstraction mechanism in FP and plays a similar role as
> classes in OOP.
>
> Their strength is that it gives one the possibility to write some algorithms
> using some type classes and then whoever wants to use it with some other
> data can do it (ever if he cannot modify their definition).
>
> There's like hundreds or thousands topics on type classes out there a google
> from you.
>
>
> My aim would be to make that usable as in Scala, using implicits.
> Maybe this one could be a good start:
> http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922493.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
So we're close..
Yes, you pass a function, and then if you need more functionnalities, you add more functions..
at a certain point, you have a lot of them (because you need more functionnalities directly or indirectly) so you decide to reduce the burden by regroup some into structures, passing less arguments.

What you end up is building type classes (which are dictionnaries, aka group of functions for a certain functionnality for a certain type).

So your solution is explicit dictionnary (functions at least) passing type classes.
What I want to do is to hide and automate this plumbing, as it is type directed, it can be hidden.

So in fact, you've self answered it! :)

Do you haskell?

Stéphane
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
In reply to this post by Juraj Kirchheim
as for subtyping, type classes are an alternatives (better or not, it depends of the usage).
'using' is interesting and very useful indeed (love it) but it is not an abstraction.


On Sun, Oct 23, 2011 at 9:34 PM, Juraj Kirchheim [via Haxe] <[hidden email]> wrote:
I am somewhat familiar with the concept of type classes as present in Haskell.
However I am not sure of their benefits in a language that supports
both structural and nominal subtyping for objects and allows for
extension through using.

That's why I asked whether there's a class of problems, where using
type classes is an advantage. The problem presented in the blog post
you mentioned really doesn't seem convincing. I mean, the way I see
it, the problem here is printing an Address as a label. Given an
Address and and a print function, I would convert the Address to a
String and the print it. And if that conversion was necessary in
multiple places, I'd put it in a static helper class, that can easily
be used with using. If "printing an address" was needed in more that
one place, then I would define a function for that. This is both clear
and short, without anything implicit - implicitness may seem cool as
you write, but when you read, it's a different beast.

But of course there might be something I am missing. I think it would
be easiest if you maybe had a piece of haXe code that seems overly
clumsy to you and show to what you would like to reduce it, given the
means you are asking for.

On Sun, Oct 23, 2011 at 8:07 PM, sledorze <[hidden email]> wrote:

> Are you asking about type classes or the way I want to bring them in scope?
>
> Type classes are an abstraction mechanism in FP and plays a similar role as
> classes in OOP.
>
> Their strength is that it gives one the possibility to write some algorithms
> using some type classes and then whoever wants to use it with some other
> data can do it (ever if he cannot modify their definition).
>
> There's like hundreds or thousands topics on type classes out there a google
> from you.
>
>
> My aim would be to make that usable as in Scala, using implicits.
> Maybe this one could be a good start:
> http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922493.html

> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922791.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

bubblebenj
I think Juraj has a point asking for a practical example.
But for another reason :
you're blowing the mailing list with all your ideas (most I can't understand cause of a lack of theorical background - and I'm confident I'm not alone).
With a concrete case we could more easily grasp the idea and thus don't pass over your post as if it were spam.

Ben

On Sun, Oct 23, 2011 at 9:56 PM, sledorze <[hidden email]> wrote:
as for subtyping, type classes are an alternatives (better or not, it depends of the usage).
'using' is interesting and very useful indeed (love it) but it is not an abstraction.


On Sun, Oct 23, 2011 at 9:34 PM, Juraj Kirchheim [via Haxe] <[hidden email]> wrote:
I am somewhat familiar with the concept of type classes as present in Haskell.
However I am not sure of their benefits in a language that supports
both structural and nominal subtyping for objects and allows for
extension through using.

That's why I asked whether there's a class of problems, where using
type classes is an advantage. The problem presented in the blog post
you mentioned really doesn't seem convincing. I mean, the way I see
it, the problem here is printing an Address as a label. Given an
Address and and a print function, I would convert the Address to a
String and the print it. And if that conversion was necessary in
multiple places, I'd put it in a static helper class, that can easily
be used with using. If "printing an address" was needed in more that
one place, then I would define a function for that. This is both clear
and short, without anything implicit - implicitness may seem cool as
you write, but when you read, it's a different beast.

But of course there might be something I am missing. I think it would
be easiest if you maybe had a piece of haXe code that seems overly
clumsy to you and show to what you would like to reduce it, given the
means you are asking for.

On Sun, Oct 23, 2011 at 8:07 PM, sledorze <[hidden email]> wrote:

> Are you asking about type classes or the way I want to bring them in scope?
>
> Type classes are an abstraction mechanism in FP and plays a similar role as
> classes in OOP.
>
> Their strength is that it gives one the possibility to write some algorithms
> using some type classes and then whoever wants to use it with some other
> data can do it (ever if he cannot modify their definition).
>
> There's like hundreds or thousands topics on type classes out there a google
> from you.
>
>
> My aim would be to make that usable as in Scala, using implicits.
> Maybe this one could be a good start:
> http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922493.html

> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922791.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..

Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
First, sorry to spam the mailing list, and frankly I somewhat feels alone with my questions so I am happy you point it out :)
I don't like to give examples because they takes a lot of time to write and are often less clear than what others already wrote..

Anyway, let's add another spam on the ML because you wan tit! :)

As I said; type classes are an abstraction tool like classes are.

Ok, let's try:

Imagine you're building a save system; and you want it to be extensible.
Use type classes you would approach it like this (pseudo code):

// this is the definition of the Serializable Type Class:
interface Serializable<T> {
  function fromBytes(b : Bytes) : T;
  function toBytes(t  : T) : Bytes;
}

now you can write some code to save some object (as long as an instance of Serializable is provided for it):


function saveToDisk<T>(data : T, dataIsSerializable : Serializable<T>) {

   var bytesToWrite = dataIsSerializable.toBytes(data);
   ....
}

so if one wants to do this:

class Toto {
  var name : String;
}

var toto = new Toto();
...

saveToDisk(toto); // there's a need here to pass an instance of Serializable<Toto>

the instance to pass is a Type Class Instance.

class TotoIsSerializable implements Serializable<Toto> {
  public function fromBytes(b : Bytes) : Toto { ... }
  public function toBytes(t  : Toto) : Bytes { ... }

  public function new() {}

  public static var instance = new TotoIsSerializable();
}

There's some things now to put in light:

- an instance of a type class for a class is a singleton and ideally (and what I was looking for) the instance passing is done under the hood, even if you can override it.

- you can save an object you cannot modify!! (and this is really really important) if you were using OOP style; you would implements the interface which bad (or you would create an object which knows how to save this specific object - but this is close to type classe, isn't it?)

this example is very simple; type classe reveal their power when building more heavy examples.
Let see how to polymorphic classes (coz it is intereting)


class Group<T> {
  var group : Array<T>;
}

so, what's its instance would look like???

class GroupIsSerializable implements Serializable<Group<T>> {

  public function fromBytes(b : Bytes, tIsSerializable : Serializable<T>) : Group<T> { ... } // here you'll have a problem with the inital interface definition, coz you need to have an instance of Serializable<T>
  public function toBytes(t  : Group<T>, tIsSerializable : Serializable<T>) : Bytes { ... } // that's why I want to have a way to adress the plumbing..

  public function new() { .. }

  public static var instance = new GroupIsSerializable();
}

and in fact you can define also Serializable<Array<T>> also, so that it simplifies a lot writing the Group instance (composition matters)

with that you can do this:

var group = new Group<Toto> ();

..

saveToDisk(group);

but also this:
var group = new Group<Array<Group<Toto>>> ();

saveToDisk(group);

without changing anything (normal).

remember; to do that; you never ever had to touch the source files of the initial Classes, ever.
if a classe changes, you only have to update it's instance.

again this is a small example which does not show the power of type classes in its full glory (that's why I hate examples).

I really really invite you to learn this concept.. a lot of people discovered it recently in the scala community, some like it, some don't get it but it's just a matter of having a better tool for certain tasks...

... that's just the best way I thing to write generic code that works with externs.. (you can pass functions dictionnaries or recreate type classes with objects, I consider this as equals because this is the same concept in disguise, just with a ton of boilerplate - the passing I want to remove)

Even if the example is not so great; I hope it hepls :)
does it?

Stephane


On Sun, Oct 23, 2011 at 10:19 PM, bubblebenj [via Haxe] <[hidden email]> wrote:
I think Juraj has a point asking for a practical example.
But for another reason :
you're blowing the mailing list with all your ideas (most I can't understand cause of a lack of theorical background - and I'm confident I'm not alone).
With a concrete case we could more easily grasp the idea and thus don't pass over your post as if it were spam.

Ben

On Sun, Oct 23, 2011 at 9:56 PM, sledorze <[hidden email]> wrote:
as for subtyping, type classes are an alternatives (better or not, it depends of the usage).
'using' is interesting and very useful indeed (love it) but it is not an abstraction.


On Sun, Oct 23, 2011 at 9:34 PM, Juraj Kirchheim [via Haxe] <[hidden email]> wrote:
I am somewhat familiar with the concept of type classes as present in Haskell.
However I am not sure of their benefits in a language that supports
both structural and nominal subtyping for objects and allows for
extension through using.

That's why I asked whether there's a class of problems, where using
type classes is an advantage. The problem presented in the blog post
you mentioned really doesn't seem convincing. I mean, the way I see
it, the problem here is printing an Address as a label. Given an
Address and and a print function, I would convert the Address to a
String and the print it. And if that conversion was necessary in
multiple places, I'd put it in a static helper class, that can easily
be used with using. If "printing an address" was needed in more that
one place, then I would define a function for that. This is both clear
and short, without anything implicit - implicitness may seem cool as
you write, but when you read, it's a different beast.

But of course there might be something I am missing. I think it would
be easiest if you maybe had a piece of haXe code that seems overly
clumsy to you and show to what you would like to reduce it, given the
means you are asking for.

On Sun, Oct 23, 2011 at 8:07 PM, sledorze <[hidden email]> wrote:

> Are you asking about type classes or the way I want to bring them in scope?
>
> Type classes are an abstraction mechanism in FP and plays a similar role as
> classes in OOP.
>
> Their strength is that it gives one the possibility to write some algorithms
> using some type classes and then whoever wants to use it with some other
> data can do it (ever if he cannot modify their definition).
>
> There's like hundreds or thousands topics on type classes out there a google
> from you.
>
>
> My aim would be to make that usable as in Scala, using implicits.
> Maybe this one could be a good start:
> http://debasishg.blogspot.com/2010/06/scala-implicits-type-classes-here-i.html
>
> Stephane
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922493.html

> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922791.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze
Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="<a href="tel:%2B33608767015" value="+33608767015" target="_blank">+33608767015" target="_blank"><a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..

Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6922900.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Heinz Hölzer-2
In reply to this post by sledorze
Am 23.10.2011 15:12, schrieb sledorze:
> inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
> ...
> }

I think it's possible to achieve this with macros.

Here is my idea:

1. Write your Class and add a build macro
@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

2) Inside of you macro change the name of foo to foo_internal and remove
the optionalExpr x.getShow()
3) add a macro function with the name foo and params x, y
4) Inside of the macro function generate the expression
     foo_internal(x, x.getShow()) // if y is null
     foo_internal(x) // if y is not null

you can skip the whole macro if display is defined, because the function
has the same signature.
You can also mark the methods with @:implicit to filter them inside of
you macro.

best,
h

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze

In fact getShow() does not exists on the parameter;
I want it to be resolved in the scope of the caller (I want to resolve a type class instance via one of its public static function because it would be accessible via a 'using' in the caller site)

So, your solution won't make getShow happend at call site..

I had a false hope when I saw the typeof method of the Context class but it does not helps either..

That's why I asked here for that particular call site code injection..

Thanks for having though about it :)
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Heinz Hölzer-2
I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html
> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Heinz Hölzer-2


Am 24.10.2011 00:06, schrieb Heinz Hölzer:
> inline public static function foo<T>(x : T, ?y : Show<T>  =
> x.getShow() ) {

please notice that this is valid haxe code and gets passed to the macro
as it is. Inside of your macro
you have to remove the optional x.getShow() because you will get a
compiler error because the expression is not constant.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
In reply to this post by Heinz Hölzer-2
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
In reply to this post by Heinz Hölzer-2
Yes, and I like the way it could be written!
what I want to achieve is really Scala implicits parameters.

any idea from function to function? (was thinking about a convention for parameter naming based on their type to be able to retrieve them..) 

Anyway, got to sleep.. :)
thanks! ;)

P.S.: will probably make progress on next free time!


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>


Am 24.10.2011 00:06, schrieb Heinz Hölzer:
> inline public static function foo<T>(x : T, ?y : Show<T>  =
> x.getShow() ) {

please notice that this is valid haxe code and gets passed to the macro
as it is. Inside of your macro
you have to remove the optional x.getShow() because you will get a
compiler error because the expression is not constant.

--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923137.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Heinz Hölzer-2
In reply to this post by sledorze
Can you post an example??

How is this done in Scala? Implicits have also scope in Scala, didn't they?

Am 24.10.2011 00:16, schrieb sledorze:
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze




View this message in context: Re: Specifying call site code from a function..
Sent from the Haxe mailing list archive at Nabble.com.




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
I won't try to compete with this excellent paper written by its creator:

Some always interesting discussions here:

Yes, Implicits have scope in scala; and that's something that worries me if I want to make them enter haXe (that's why I want to use by convention naming which has scope; however, I realize that Type class with dependencies could remain problematic (have to think more about it) )..

Back to real work now.. :)


P.S.: We're bending a lot haXe to bring that (would be nice to have implicits natively)

2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
Can you post an example??

How is this done in Scala? Implicits have also scope in Scala, didn't they?

Am 24.10.2011 00:16, schrieb sledorze:
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>

I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..

Sent from the Haxe mailing list archive at Nabble.com.




--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6924806.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Heinz Hölzer-2
In reply to this post by sledorze
But replacing a function with a macro has also some flaws. You can't store them in variables or apply them partially.





Am 24.10.2011 00:16, schrieb sledorze:
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze




View this message in context: Re: Specifying call site code from a function..
Sent from the Haxe mailing list archive at Nabble.com.




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

sledorze
That's true; and that's why this work could at best be a proof of concept and whoever know what would be the ideas it could generate..
It looks like that's a way I like wasting time.. :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
But replacing a function with a macro has also some flaws. You can't store them in variables or apply them partially.






Am 24.10.2011 00:16, schrieb sledorze:
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>

I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..

Sent from the Haxe mailing list archive at Nabble.com.




--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6924945.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: Specifying call site code from a function..

Tarwin Stroh-Spijer
Don't see what you're doing as spam, but would be good to keep things to replies to your posts (same heading) if they're related - just to make sure people CAN ignore if they want.

The lenses thing isn't something I think I'd use - but it's nice to learn the theory of it, and that it's possible.

Regards,


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Mon, Oct 24, 2011 at 11:56 PM, sledorze <[hidden email]> wrote:
That's true; and that's why this work could at best be a proof of concept and whoever know what would be the ideas it could generate..
It looks like that's a way I like wasting time.. :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>
But replacing a function with a macro has also some flaws. You can't store them in variables or apply them partially.






Am 24.10.2011 00:16, schrieb sledorze:
Oh, that's clever indeed :)
That would mean that all user code should be written in a macro transformed class..
.. at least; that's a solution!

Now there's a solution for the capture; I need to see how to pass that information to nested function calls (where the using trick can't work because it is no more in scope).

Thanks! :)


2011/10/24 Heinz Hölzer-2 [via Haxe] <[hidden email]>

I'm not sure if i understand you correctly, but in my example the
replacement does happen on the call side.

@:build(MyMacro.transform())
class A {

inline public static function foo<T>(x : T, ?y : Show<T>  = x.getShow() ) {
...
}
}

gets transformed to

@:build(MyMacro.transform())
class A {

@:macro public static function foo(x : Expr, ?y : Expr ) {
     return
         if (y == null) makeExpr("A.foo_internal(x, x.getShow())")
         else makeExpr("A.foo_internal(x, ${y})", y); // pseudocode
}


inline public static function foo_internal<T>(x : T, y : Show<T>) {
...
}
}

so a call to

A.foo(x)

gets transformed to

A.foo_internal(x, x.getShow())

best,
h

Am 23.10.2011 23:52, schrieb sledorze:

> In fact getShow() does not exists on the parameter;
> I want it to be resolved in the scope of the caller (I want to resolve a
> type class instance via one of its public static function because it would
> be accessible via a 'using' in the caller site)
>
> So, your solution won't make getShow happend at call site..
>
> I had a false hope when I saw the typeof method of the Context class but it
> does not helps either..
>
> That's why I asked here for that particular call site code injection..
>
> Thanks for having though about it :)
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923095.html

> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6923124.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze
Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="<a href="tel:%2B33608767015" value="+33608767015" target="_blank">+33608767015" target="_blank"><a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..

Sent from the Haxe mailing list archive at Nabble.com.




--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/Specifying-call-site-code-from-a-function-tp6921986p6924945.html
To unsubscribe from Specifying call site code from a function.., click here.



--
Stéphane Le Dorze


Tel: <a href="tel:%2B33%20%280%29%206%2008%20%C2%A076%2070%2015" value="+33608767015" target="_blank">+33 (0) 6 08  76 70 15




View this message in context: Re: Specifying call site code from a function..
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
12