Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several options available to handle I/O in a functional language.</p> <ul> <li>Don't be pure. Many functional languages aren't purely functional. It's more that they <em>support</em> functional programming rather than enforcing it. This is by far the most common solution to the problem of I/O in functional programming. (Examples: Lisp, Scheme, Standard ML, Erlang, etc.)</li> <li>Stream transformation. Early Haskell I/O was done this way. Check my link below for details if you want more information. (Hint: you probably don't.)</li> <li>Continuation-passing I/O (the "world-passing" mentioned in other answers). In this one you pass a token of data around with your I/O that acts as the necessary "different value" to keep referential integrity alive. This is used by several ML dialects if memory serves.</li> <li>The "continuation" or "world" thing above can be wrapped in various data types, the most (in)famous being the use of monads in this role in Haskell. Note that this is, notionally, the same thing under the covers, but the tedium of keeping track of "world"/"continuation" state variables is removed.</li> </ul> <p>There's <a href="https://docs.google.com/viewer?url=http://research.microsoft.com/en-us/um/people/adg/publications/fpio.pdf" rel="noreferrer">a research dissertation</a> that exhaustively analyses these.</p> <p>Functional I/O is an ongoing field of research and there are other languages which address this issue in interesting and mind-mangling ways. <a href="http://en.wikipedia.org/wiki/Hoare_logic" rel="noreferrer">Hoare logic</a> is put to use in some research languages. Others (like <a href="http://en.wikipedia.org/wiki/Mercury_(programming_language)" rel="noreferrer">Mercury</a>) use <a href="http://en.wikipedia.org/wiki/Uniqueness_type" rel="noreferrer">uniqueness typing</a>. Still others (like <a href="http://en.wikipedia.org/wiki/Clean_(programming_language)" rel="noreferrer">Clean</a>) use <a href="http://en.wikipedia.org/wiki/Effect_system" rel="noreferrer">effect systems</a>. Of these I have a very, very limited exposure to Mercury only, so I can't really comment on details. There's a <a href="http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=E725ADC5F4F4B360A1209DB64B3B2237?doi=10.1.1.17.935&amp;rep=rep1&amp;type=pdf" rel="noreferrer">paper</a> that details Clean's I/O system in depth, however, if you're interested in that direction.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload