Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Is this supposed to be Haskell code or Haskell semantics?
Perl-Code to show the general idea of how to apply lazy evaluation, not restricted to Haskell (which is just one of the languages having lazy evaluation builtin).
Using Tie::Array you could try to tie the iterator to an array @even such that you can subsequently write something like this, _with_ lazy evaluation.
Good point!
show me what you like about Haskell - eg list comprehensions (???) - and I will see whats feasible.
I'm not an advocate for a particular language (Haskell was just given as an example, because several implementations are available), but I like the idea in FP that you don't have side effects. This is nice for the programmer, but can be hairy for the implementation. List comprehension helps if you transform arrays, but I think array update is more tricky. Where you write in an imperative language something like $a->[$n]+=$k to update the array element at postition $n, you would in FP (conceptionally) return a copy of the array, which differs from the original one only in the element with index $n. Of course you don't want to actually copy the whole array, unless it is really necessary. For instance, if you have an array $a and a function &fa expecting an array (I stay with Perl syntax here), and you want to invoke the function with $a, but set the first element of $a to zero, the non-functional solution would be simply

$a->[0]=0; fa($a);
while a functional solution would need something like
fa(update($a,0,0))
and need to be clever enough to not make a copy of the array until this is becomes necessary. But a guess with a clever usage of tied variables and Perl objects, you might indeed be able to come up with a FP framework for Perl...

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re^9: Next Language to Learn (Lazy Perl) by rovf
in thread Next Language to Learn by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found