Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Anonymous Monk
on Jun 11, 2007 at 21:55 UTC ( [id://620585]=note: print w/replies, xml ) Need Help??


in reply to Re: 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 ?

You may be interested to know that Haskell did not always use monads for I/O. This paper describes three alternative, purely functional methods for implementing I/O in Haskell that were used before monads:

http://citeseer.ist.psu.edu/30726.html

It is also important to note that monads not special things wired into the compiler. They are built using normal Haskell code and live in the standard libraries.

It is quite possible to write real programs in Haskell without using any monads. Of course, you would probably just reinvent them without realizing it.

  • Comment on Re^2: Is it worth using Monads in Perl ? and what the Monads are ?

Replies are listed 'Best First'.
Re^3: Is it worth using Monads in Perl ? and what the Monads are ?
by BrowserUk (Patriarch) on Jun 11, 2007 at 22:27 UTC
    On the Expressiveness of Purely Functional I/O Systems

    It's possibly a very interesting paper, but all I can find online are citations and references--which means it might as well be printed in a 9 point font on the Moon for all the accessability it has.

    It is also important to note that monads not special things wired into the compiler. They are built using normal Haskell code and live in the standard libraries.

    That sounds promising. Care to show an example of how to read from stdin and write to stdout without using a IO Monad? Or just perform an question and answer session interactively without them/it?

    It is quite possible to write real programs in Haskell without using any monads.

    Again, care to post an example that can be compiled with GHC v6.4?


    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.

      On the page I linked to, in the top-right hand corner, there are links to the paper in several different formats.

      The paper includes a bunch of examples. As far as I know, there is no fundamental reason why those libraries could not be used with a modern version of GHC.

      A simple experiment you can do to see what non-monad I/O is like is to use the interact function.

      main = interact yourFunction
      yourFunction is a pure function which takes a lazy list of Strings (which are gathered from stdin), and returns a lazy list of strings (which are written to stdout).

      For some examples, (such as interactive questions using stdin/stdout) check out this page:
      http://cod3po37ry.blogspot.com/2007/02/more-on-haskell-io-and-interact.html

      Although interact is currently implemented in the IO monad, I believe it pre-dates monadic IO.

      ...all I can find online are citations and references...
      What happens when you click on the PDF link in the light blue box in the upper left hand corner? What about this link instead?

        Okay. I missed that. Small text and rapidly diminishing eyesight (it's late here).

        At a cursory glance, it's still smoke and mirrors :) Take the streams example. It fetches a list of filenames from the keyboard and then displays them.

        It then explains that referential transparency is maintained, even if the same filename is supplied twice and some other program changes that file between the two reads--giving different output from the file_display function for the same input--because:

        ...there is no lexical connection between a request and a response. Thus, although two differemt read requests of the same file are equivalent values, their effect will depend upon their position in the list, they could each invoke a different response, reflecting the fact that the file may have been modified between the two reads.

        Hand transcribed because c&p from the pdf produces garbage! I hate pdfs.

        So, by that definition of referrential transparency, if I have a function f, which takes a list of numbers and returns a list of numbers having doubled them. And I supply a list [2,2,2,2,2] and it returns [-1, 217,'fred',12345678901234567890, null], that's legit, referential transparency wise, because although the inputs are all the same value, they also have position. And the input to the function was a list and the output was a list. And provided that if I pass in another list containing the same values, I get the same output list everything is okay.

        But...if I supply the same list of two identical filenames to file_display a second time, I would get different output from the first time! Because the file remains changed from the first time it was read. (And could have changed again.) So, same input list, same positions, produces different output.

        Smoke and mirrors!

        Further discussion should probably be off-post. (Email on my home node if your a different anonymonk to the other anonymonk :)


        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.
        Whoops, I meant to say "upper right hand corner". Sorry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found