Thanks for the clarification.<br><br>>AFAIK, the only way to get input and produce output is via the IO monad<br><br>Now you know something different, don't you? FRP, Pan, TV. Also Grapefruit, functional forms, and others I'm not thinking of or don't know about.
<br><br>As for your example, mixing the IO with the functional, as you have interferes with composing the result. I can think of two alternatives. One is to move reading & printing from the definition to the uses, as with Unix stream filters. Still convenient, and much more flexible. Of course, Unix programs were written in C and so use explicit I/O instead of lazy functional streams. (Though Doug McIlroy, who invented Unix pipes, knew that pipes were equivalent to coroutines and to lazy evaluation. See my "modern marriage" talk (the video I mentioned) for more about Unix and TV.)
<br><br>A second alternative is to use TV to explicitly capture the interface (I/O), which could look like this:<br><br> coolTV :: TV (String -> String)<br> coolTV = tv (olambda (fileIn "Data.txt") defaultOut)
<br> performAwfullyCoolFunctionalStuff<br><br>where<br><br> tv :: Output src snk a -> a -> TV src snk a<br><br>The type parameters src & snk are for various interface styles. Then coolTV can then be used on *either* side of a TV-style pipe, resulting in the removal of the reading or writing half.
<br><br>And yes, there are *some* uses of IO for which I'd be hard pressed at this point to offer you an alternative. Which is a far cry from IO being necessary for all "real" programs, even today.<br><br>Given this state of affairs, I'd prefer the Haskell community to point newbies away from IO and toward purely functional programming for things like UIs and graphics and help them change their way of thinking. Let's also admit that we haven't yet figured out how to apply our functional paradigm as flexibly or broadly as we'd like, and so meanwhile we have thi monadic IO trick that let's them write nicely factored imperative code that can call into the functional pieces.
<br><br>Regards, - Conal<br><br><div class="gmail_quote">On Dec 9, 2007 12:54 PM, Daniel Fischer <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Am Sonntag, 9. Dezember 2007 21:29 schrieb Conal Elliott:<br><div class="Ih2E3d">> I think your real point is that some things we still haven't figured out<br>> how to express functionally. Right?<br><br></div>
That's my point, at least. Currently, AFAIK, the only way to get input and<br>produce output is via the IO monad, so it is de facto necessary for all<br>'real' programmes, it need not remain so (though I cannot imagine how to
<br>functionally express<br>'readFile "Data.txt" >>= print . performAwfullyCoolFunctionalStuff' - surprise<br>me :).<br>Read "IO is important" as a description of current affairs, not as a claim of
<br>the inherent grandeur of it.<br><br>Cheers,<br><font color="#888888">Daniel<br></font><div><div></div><div class="Wj3C7c"><br>> I would certainly agree with that<br>> part. Perhaps you exaggerating when you wrote "IO is important because you
<br>> can't write any real program without using it."<br>><br>> Cheers, - Conal<br>><br><br></div></div></blockquote></div><br>