|From: "Shah Namrata Abhaykumar" <[EMAIL PROTECTED]>
|Subject:      Haskell I/O
|
|I am trying to understand I/O in haskell. I have trouble understanding
|how it is referentially transperant ?

|Consider that main is,
|
|        main resps = [req1,req2,req3,req4]
|                     where req1 = ..
|                           req2 = .... (tl resps) ....
|                           req3 = .... (tl resps) ....
|                           req4 = ..
|
|As, req1,..,req4 are all evaluated in the environment with a binding for
|resps, both (tl resps) in req2 and req3 should evaluate to same
|expression (referential transperancy). But when req2 is evaluted,
|resps = [response_to_request1] and when req3 is evaluated,
|resps = [response_to_request1, response_to_request2].

No, the list resps does not change, although it is evaluated lazily.

|Hence, (tl resps) in req2 and req3 donot evaluate to the same value.
|Isn't referential transperancy lost ? In other words, the binding
|for resps keep on changing i.e. there is some side effect occuring
|somewhere.

There are no side effects in the Haskell program, which is a pure function
from streams of responses to streams of requests.  We may, however, regard
the operating system that interprets the requests and delivers the
responses as acting on the requests in order and producing effects on
the file system.

|       This is the picture that I have drawn after reading Haskell
|I/O. I may be wrong somewhere. Correct me if I am wrong.
|
|-Namrata Shah
|([EMAIL PROTECTED])

I hope my explanation has helped.

Cheers,
--Joe

Reply via email to