4 ms·
Can anyone explain to me how the io monad gives referential transparency? So, say I have a function to read a file: readFile :: String -> IO String readFile
by anonymousDan 17y ago
Can anyone explain to me how the io monad gives referential
transparency?
So, say I have a function to read a file:
readFile :: String -> IO String
readFile filename = ...
At time t1, if I invoke it it returns say:
IO "Contents at t1"
At time t2, if I invoke it it returns say:
IO "Contents at t2"
Given that we supplied the function with the same
argument (i.e. fname), and it returns two different values,
how can they be said to be equal? I'm probably totally misunderstanding this but anyway....
- yummyfajitas 17y agoIt isn't just IO that breaks referential transparency, State does the same thing. The function get might have different values at different times. Of course, get is a pure function mapping (State a) -> (State a) a, and the value hidden in the state is different between successive function calls. Now just treat IO as State World, and think of the compiler as the function execState initialWorldValue.