Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^11: Is it worth using Monads in Perl ? and what the Monads are ?

by BrowserUk (Patriarch)
on Jun 15, 2007 at 10:29 UTC ( [id://621432]=note: print w/replies, xml ) Need Help??


in reply to Re^10: Is it worth using Monads in Perl ? and what the Monads are ?
in thread Is it worth using Monads in Perl ? and what the Monads are ?

But surely, the compiler could have figured this out at least?

Hm. One way of reading it is that Haskell defaults to assuming that all functions are pure unless a monad is used, in which case they aren't. And it's the programmer that has to know to when to use the monad. Which goes back to my "monads are a complicated form of flag". Yes, I know it's more complicated than that...

Perl is the other way around. All functions are impure unless the programmer knows otherwise. It would be possible to use (say) attributes to allow the programmer to mark functions pure and the compiler could automemoize them on that basis. Maybe there is even a module idea in there somewhere.

For sure, Perl does no where near the depth of analysis that ghc does--but that is true in almost every area. Objects for instance. And maybe it's not possible without strict typing. But it is also a concious choice on behalf of the the language designers, hence Perl 6 won't have HM-style type checking either.

Is that the right decision? You'd have to argue that with Mr Wall. But without Perl's transparent coersion between strings, integers and reals (and Big::*), Perl would not be Perl.

Haskell and Perl go about achieving what they do--programs--in different ways. We all know that. This is not (for me) about which is better. It's about whether Perl could benefit from the inclusion of a monad type mechanism, to which I say emphatically no. Even if it could be implemented, without an HM-style type system, and a deep analysing compiler, it would be another manual process adding a drain on performance, without the benefits. Adding HM-style type checking to Perl (or any dynamic language) would be fairly impractical, but even if it was practical, I personally wouldn't want it. If I wanted that, I wouldn't be using Perl.

Haskell (often) sells itself on the strength of a few elegant snippets--like the quicksort routine using list comprehensions, but when you look beyond those snippets, much of the gloss is tarnished. It's a little like the Quantum::Superpositions module. When you first encounter it, especially the documentation in the form of what I am sure was a spectacular presentation, it really wows you. But when you look inside, you realise--as someone here commented--it's just a bunch of loops. That doesn't make the module any less powerful in what it does--though it is a little slow for some of it's less esoteric possible uses. What it does mean is that when you understand how it does what it does, the wow factor of the documentation/presentation fades somewhat. If the documentation was less wow, more down to earth, it might engender less ire. I'm pretty certain that Junctions will become a big factor in the success of Perl 6, assuming they are documented in a less hyperbolic fashion and are reasoably fast.

Haskell is a fine, powerful, flexible, fast, elegant language--if you like or need that sort of thing and can make the mental shift to that way of thinking. It doesn't need the hyperbole.

I've tried to keep this subthread on topic, but our interaction is rapidly descending into a which is better debate. Unless you think that Perl would benefit from the addition of a monad-like mechanism, I think we are probably done?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^11: Is it worth using Monads in Perl ? and what the Monads are ?

Replies are listed 'Best First'.
Re^12: Is it worth using Monads in Perl ? and what the Monads are ?
by Errto (Vicar) on Jun 15, 2007 at 23:49 UTC
    One way of reading it is that Haskell defaults to assuming that all functions are pure unless a monad is used, in which case they aren't.

    I have some modest Haskell experience myself, and I admit I learned about monads the "wrong" way (starting "as a way to do IO"), but I've come to look at it a bit differently. To my mind, monads let you compose code in a more procedural-esque style without worrying so much about the stuff going on in the background, or whether that stuff involves side effects or not. The thing is, most Haskell monads actually are purely functional in that when you actually expand them out and evaluate them they boil down to simple computations that don't touch the state of the outside world - arguments in, return value out, nothing more to it.

    This does mean, to my mind, that Perl is fairly unlikely to benefit much from monads, because there's no need for that sort of simulation. And I agree with you that absent static type-checking, the fact that a monad's very existence constrains the operations allowed within it becomes less useful.

Re^12: Is it worth using Monads in Perl ? and what the Monads are ?
by gaal (Parson) on Jun 15, 2007 at 16:36 UTC
      I've tried to keep this subthread on topic, but our interaction is rapidly descending into a which is better debate. Unless you think that Perl would benefit from the addition of a monad-like mechanism, I think we are probably done?
    I didn't get the feeling I was saying Haskell's better; I was merely trying to give meaning as to what's good about (an aspect of) it. I kinda like Perl, myself! And no, I wan't saying Perl needed monads anywhere. So sure, if there was a debate aspect to this conversation, I suppose we could wrap it up.

    Except :-)

    I have to say I felt mentioning Quantum::Superpositions here was something of a strawman. Or even, two strawmen. "It's just a bunch of loops" smells like the notorious expression "It's just a way to arrange JMPs". There's expressive power offered here, even if the implementation emulates something using loops. And secondly, presumably once the technology arrives whence the module got its name and inspiration, the implementation would cease to be an emulation, and the operations would become primitives. But we can drop this too...

Log In?
Username:
Password:

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

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

    No recent polls found