Chris Angelico <ros...@gmail.com>:
> If you want to prove to me that monads are still functional,

Ultimately, monads are simply the pipelining pattern. It is used
extensively in Unix shells. (I don't know Microsoft's PowerShell, but it
used to be called "Monad".)

> Otherwise, what you're really saying is "we can cheat until we can do
> I/O", not "we can do I/O in a functional way".

I guess it's justified as follows: in functional programming, your
program is a function that produces an output out of its input. IOW:

    program(input)
    => output

Because of lazy evaluation, the program can start before the input is
prepared and output can be returned gradually before the program
finishes. This principle is analogous to Python's generators:

   def program(input):
       for data in input:
           whenever output is produced:
               yield output

Similarly, a Haskell program can take in lines, keypresses, mouse clicks
etc through its input stream and consume the stream gradually, and
generate lines, sounds, animation etc to its output stream gradually.

That gradual inputting and outputting can be carried out purely
functionally. Consider, for example, the task of finding a zero in an
infinite stream of numbers in Python:

    def skip_over_zero(stream, cont):
        if stream.head() == 0:
            return cont(stream)
        return skip_over_zero(stream.tail(), cont)        


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to