Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Simulating Perl6 Meta/Hyper operators with pure Functional Programming

by moritz (Cardinal)
on Oct 01, 2013 at 18:54 UTC ( #1056520=note: print w/ replies, xml ) Need Help??


in reply to Simulating Perl6 Meta/Hyper operators with pure Functional Programming

I'm not an authority on pure functional programming, and I don't have any working code, so takes this with a grain of salt. But this:

Only the rightmost X has the information about the operation and there is only one slot free to pass an iterator.

Is it possible to write the intermediate (and final) iterators in a purely functional way that the operation (here plus) is incapsulated within the logic of the passed iterators?

sounds an awful lot like you solve the "only one free slot" problem by returning a more complicated object, like an array ref of [$operator, $iterator]. Of course that changes the calling convention of the subsequent operations, and you'll likely want to write a lift function that deals with the changed calling convention for you. And congratulations, you have invented monads.

Which is, of course, the way to solve problems in purely functional languages which you'd solve with state in impure languages.


Comment on Re: Simulating Perl6 Meta/Hyper operators with pure Functional Programming
Select or Download Code
Re^2: Simulating Perl6 Meta/Hyper operators with pure Functional Programming
by LanX (Canon) on Oct 01, 2013 at 22:17 UTC
    > you'll likely want to write a lift function

    An important part of the concept is to return an iterator to the LHS in scalar context for the laziness an array-ref wouldn't help.

    And there is no context info which tells me if an X {} is nested or already at the RHS of an assignment.

    (OK I could use metamagic like Damian's Contextual::Return which I never really understood, I'm still suspicious that it might be a April's fool joke)

    > you have invented monads.

    kind of ... already in 2011 ... see YAPC talk

    (well even earlier if you count in Frankfurt Perl Workshop)

    > the way to solve problems in purely functional languages

    OK ... needs disambiguation. I don't really care here about side effects, which is the motivation for monads in Haskell.

    But solutions which "only" work with code-references and closures (i.e. w/o blessing or other magic) have many benefits ... like portability.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-07-29 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls