
On 2009 Apr 9, at 22:47, Brandon S. Allbery KF8NH wrote:
-- these implicitly are considered to return a modified RealWorld readFile :: RealWorld -> (String,RealWorld) writeFile :: RealWorld -> ((),RealWorld) threadDelay :: RealWorld -> ((),RealWorld)
main :: RealWorld -> ((),RealWorld) main state = case readFile state "/my_file" of (s,state') -> case writeFile state' "/my_file" "Hello, world!\n" of (_,state'') -> case threadDelay state'' 10000 of (_,state'') -> writeFile "/my_file" s
Sorry, the last line should be:
(_,state''') -> writeFile state''' "/my_file" s
This code is nothing more nor less than the translation of Jonathan Cast's code, using a presumptive
type IO a = State RealWorld a
into "linear" de-monadified code. Clearly the state is threaded into main, through all the calls, and the final state returned; the state threading is what maintains the referentially transparent model. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH