Lenses macros available.

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

Lenses macros available.

sledorze
http://lambdabrella.blogspot.com/2011/10/compile-time-generation-of-lenses-in.html

Got to force myself not doing some macros.. :)

Feel free to comment!



Reply | Threaded
Open this post in threaded view
|

Re: Lenses macros available.

Tarwin Stroh-Spijer
OK. So if I get this right, lenses are used like some kind of reference to a drill-down into a class, or set of them?

So I can almost use it like an SQL statement in a way. In the example here it's like "UPDATE user SET age = 'N' WHERE lead = true" or some such. Is this kind of correct?

Regards, 


Tarwin Stroh-Spijer
_______________________

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


On Sun, Oct 23, 2011 at 8:35 AM, sledorze <[hidden email]> wrote:
http://lambdabrella.blogspot.com/2011/10/compile-time-generation-of-lenses-in.html

Got to force myself not doing some macros.. :)

Feel free to comment!





--
View this message in context: http://haxe.1354130.n2.nabble.com/Lenses-macros-available-tp6920985p6920985.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: Lenses macros available.

sledorze
Yeah in some way; I've only implement the basics, you can provide more extensions to have more expressivity.
Like handling containers datastructures (it's explained in the videos I linked).

Lenses are very useful when you want to use a function that knows how to manipulate some data and apply it in a nested structure.
Using those saves you to write all the boilerplate of accessing and reconstructing the objects by hand.

Remember; in their current incarnation; there're immutables (i.e copy instead of mutation in place) which has advantages as a declarative approach to things but don't play with stateful (aka imperative) datastructures.

You see their immutable approach as any operation via a lense returns a new root for the whole datastructure (which shares all the same objects but those on the path down to the modification).

However, you may implement imperative lenses if you will.. (but that does not make a lot of sense as your better just use a reference)
..here the macro part which is responsible for the immutable approach:

   var exprString = Std.format("
      { 
        get : function (___obj : $typeName) return ___obj.$cname,
        set : function ($cname : $cTypeName, ___obj : $typeName) {
          var ___cp = Reflect.copy(___obj);
          ___cp.$cname = $cname;
          return ___cp;
        }
      }
    ");

In its video he talks about using it with the state monad; this is very smart as it makes function working with state monad able to compose.cleanly.

Lenses are very usefull when working for manipulating datastructures functionnaly.
So you may not find any usage in your daily code, until you do! :)

I hope it helps,
Stephane


On Tue, Oct 25, 2011 at 12:10 AM, Tarwin Stroh-Spijer [via Haxe] <[hidden email]> wrote:
OK. So if I get this right, lenses are used like some kind of reference to a drill-down into a class, or set of them?

So I can almost use it like an SQL statement in a way. In the example here it's like "UPDATE user SET age = 'N' WHERE lead = true" or some such. Is this kind of correct?

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 Sun, Oct 23, 2011 at 8:35 AM, sledorze <[hidden email]> wrote:
http://lambdabrella.blogspot.com/2011/10/compile-time-generation-of-lenses-in.html

Got to force myself not doing some macros.. :)

Feel free to comment!





--
View this message in context: http://haxe.1354130.n2.nabble.com/Lenses-macros-available-tp6920985p6920985.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/Lenses-macros-available-tp6920985p6926749.html
To unsubscribe from Lenses macros available., click here.



--
Stéphane Le Dorze