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
|

Re: Specifying call site code from a function..

bubblebenj
Let me disambiguate, I didn't say it was spam.
I said since I don't understand most of it, I could ignore it as if it were spam.

Anyway the example was clear enough to grasp the idea.

Ben

On Tue, Oct 25, 2011 at 12:17 AM, Tarwin Stroh-Spijer <[hidden email]> wrote:
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: <a href="tel:%2B61%203%208060%205321" value="+61380605321" target="_blank">+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


--
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
In reply to this post by sledorze
Call site code is nice from the user side, but the problem from my point of view is that you have to write a lot of code on the definition side.

Take Ord as an Example, it would look something like:

class Ord<T> {
 
  public function compare (a:T, b:T, equals:Eq<T>):Ordering {
    return if      (equals.eq(a, b))   EQ
           else if (lessOrEq(a, b, equals)) LT
           else                     GT;
  }
 
  public function less (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) == LT;
  }
 
  public function lessOrEq (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) != GT;
  }
 
  public function greaterOrEq (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) != LT;
  }
 
  public function greater (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) == GT;
  }
 
  public function min (a:T, b:T, equals:Eq<T>):T {
    return lessOrEq(a, b, equals) ? a : b;
  }
 
  public function max (a:T, b:T, equals:Eq<T>):T {
    return greaterOrEq(a, b, equals) ? a : b;
  }
 
}

with

class Eq<T> {
  public function eq (a:T, b:T):Bool {
    return notEq(a, b);
  }
 
  public function notEq (a:T, b:T):Bool {
    return !eq(a, b);
  }
}


you have to pass each constraint to all functions and this leads to a problem with inheritance:

how would you express this:

  1. instance (Eq m) => Eq (Maybe m) where  
  2.     Just x == Just y = x == y  
  3.     Nothing == Nothing = True  
  4.     _ == _ = False  
  5.        
// something like

class Eq<Maybe<T>> extends Eq<Maybe<T>> {
  public function eq (a:T, b:T, eq:Eq<T>):Bool {
   ...
  }
}

but this does not work, because you need an additional parameter for each function.

I would really like to see something like Type Classes in haxe, especially because you cannot modify plattform specific types and classes. But i cannot see a way to express it in haxe.

Am 24.10.2011 00:26, schrieb sledorze:
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




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 don't see any inheritence problems if we formulate it another way.
And a nicer way to deal with type class constraints; passing them to an instance we construct.

class Ord<T> {

  var teq : Eq<T>;  
  public function new(teq : Eq<T>) {
    this.teq = teq;
  }

 public function compare (a:T, b:T):Ordering {
    return if      (teq .eq(a, b))   EQ
           else if (lessOrEq(a, b)) LT
           else                     GT;
  }
  
  public function less (a:T, b:T):Bool {
    return compare(a, b) == LT;
  }
 ...
}

same stuff apply to Eq<Maybe<T>>, the only contract we have to respect is type class interface; the constructor exactly reflecting the constraints you may find in the haskell constraint parameters: instance (Eq m) => 

class MaybeEq<T> extends Eq<Maybe<T>> {
  
  public function new(teq : Eq<T>) {
   ...
  }  
  ...
}


this requieres building an instance that would be passed from functions to functions, capturing, at its creation, its type classes instance parameters.

That is the reason why I've asked in previous mails the ability to scope using and, most importantly; to use it with variables instances.

so bringing this into scope:

using maybeTEq; // instance singleton retrievial for each type could still be done via a static function (eventually generated by a macro).

one can use that:

a.eq(b);

which would translate into:

maybeTEq.eq(a, b);


I also think that taken separately; call site instanciation and using with variables are both valuable; for instance; the former to get speed by inlining some code before a call (+to capture implicits) and the latter to reduce boilerplate and providing sincer API usages.

Stephane


2011/11/14 Heinz Hölzer-2 [via Haxe] <[hidden email]>
Call site code is nice from the user side, but the problem from my point of view is that you have to write a lot of code on the definition side.

Take Ord as an Example, it would look something like:

class Ord<T> {
 
  public function compare (a:T, b:T, equals:Eq<T>):Ordering {
    return if      (equals.eq(a, b))   EQ
           else if (lessOrEq(a, b, equals)) LT
           else                     GT;
  }
 
  public function less (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) == LT;
  }
 
  public function lessOrEq (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) != GT;
  }
 
  public function greaterOrEq (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) != LT;
  }
 
  public function greater (a:T, b:T, equals:Eq<T>):Bool {
    return compare(a, b, equals) == GT;
  }
 
  public function min (a:T, b:T, equals:Eq<T>):T {
    return lessOrEq(a, b, equals) ? a : b;
  }
 
  public function max (a:T, b:T, equals:Eq<T>):T {
    return greaterOrEq(a, b, equals) ? a : b;
  }
 
}

with

class Eq<T> {
  public function eq (a:T, b:T):Bool {
    return notEq(a, b);
  }
 
  public function notEq (a:T, b:T):Bool {
    return !eq(a, b);
  }
}


you have to pass each constraint to all functions and this leads to a problem with inheritance:

how would you express this:

  1. instance (Eq m) => Eq (Maybe m) where  
  2.     Just x == Just y = x == y  
  3.     Nothing == Nothing = True  
  4.     _ == _ = False  
  5.        
// something like

class Eq<Maybe<T>> extends Eq<Maybe<T>> {
  public function eq (a:T, b:T, eq:Eq<T>):Bool {
   ...
  }
}

but this does not work, because you need an additional parameter for each function.

I would really like to see something like Type Classes in haxe, especially because you cannot modify plattform specific types and classes. But i cannot see a way to express it in haxe.


Am 24.10.2011 00:26, schrieb sledorze:
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


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-tp6921986p6992216.html
To unsubscribe from Specifying call site code from a function.., click here.
See how NAML generates this email



--
Stéphane Le Dorze


12