On the bus ride out to Charleroi I caught a stray brainwave about how to properly notate at least some of Haskell's Lens library, so I wrote up some notes on it. This is going to be slightly spooky, but not much more than the previously-existing ability to bind one data structure to another. I don't know if this is in the spirit of the Haskell library, as it relies heavily on types and type transformations, but I gather that types don't perform quite the role they do in Perl 6. We could conceivably make the lens type-aware so that a lot of mechanism could go away, but the code below has the general idea. The 'lens' library is essentially a metaphor for focussing in on your data, in roughly the following sense:
my $lens = Optical::Bench::BeamSplitter.new; $a =< $lens >= $b; # Think of $a "passing through" $lens into $b. $a = 'foo bar'; is-deeply $b, [ 'foo', 'bar' ]; $b.[1] = 'moo'; is $a, 'foo moo';
Lenses can be chained:
my $lens2 = Optical::Bench::BeamSplitter.new('-'); $a =< $lens >=< $lens2 >= $b; $a = 'foo-bar baz-qux'; is-deeply $b, [ [ 'foo', 'bar' ], [ 'baz', 'qux' ] ];
If that behavior is a little too magical, use the '<<' and/or '>>', and then the changes only go in one direction, or none at all (but they'll still happen on binding.)
$a << $lens >= $b; $a = 'foo bar'; is-deeply $b, [ 'foo', 'bar' ]; # ok 1 $b.[0] = 'moo'; is-deeply $b, [ 'moo', 'bar' ]; is $a, 'foo bar'; # ok + 2, ok 3
If you're having trouble coming up with a use for this, envision database work, where you have a transform (like, say, converting timestamps) you need to do on the way in and out of the database:
my $lens = O::B::mySQL.new('Mmm dd, yyy'); $created-date =< $lens >= $created-date-mySQL; is $created-date, 'Feb 3, 2016'; is $created-date-mySQL, '2016-02-03T09:50+02:00';
Put this anywhere in your method, and you can rest assured that the mySQL date will be formatted correctly when it gets saved. With sufficient black magic, it might even work like:
$post.<created-date> =< O::B::mySQL::Date.new >= $params.<created>;
so you could drop that into your Dancer'ish Controller, or maybe even directly in your database Model, once there's an ORM thing for Perl 6.

In reply to Focussing Haskell into Perl 6 by DrForr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.