[m-users.] Can I turn an impure function into a semi-det pure function

Mark Brown mark at mercurylang.org
Sat Jun 27 07:44:57 AEST 2015

Hi Charles,

On Sat, Jun 27, 2015 at 6:24 AM, Charles Shuller
<charles.shuller at gmail.com> wrote:
> More specifically, I want to fetch something from a web-server.
> If I understand things correctly, this is a very impure thing to do, since
> the results don't really depend much on the parameters.  For instance, the
> contend returned can change between requests.
> But if this function is impure, then it seems my entire program must also be
> impure, which I would really rather avoid.

This is no different from reading any other kind of input, as far as
referential transparency is concerned. So the usual technique is to
model this by passing the current io state in and getting a new one
back, along with the input results.

Generally, though, you don't have to use the io state for this
purpose. Any type for which there is a distinct value for each
possible state the web server can be in will suffice to ensure that
the results depend on the parameters, as you say.


More information about the users mailing list