-
-
Save ympbyc/4362024 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IO a -> a | |
function unsafePerformIO (io) { | |
var tuple = io({"memo" : "This is the real world!!"}); | |
var newWorld = tuple[0]; | |
var value = tuple[1]; | |
return value; | |
} | |
// IO a -> (a -> IO b) -> IO b | |
function bind (io1, f) { | |
return function (world) { | |
var tuple = io1(world); | |
var newWorld = tuple[0]; | |
var value = tuple[1]; | |
var io2 = f(value); | |
return io2(newWorld); | |
}; | |
} | |
// String -> IO () | |
function alertIO (message) { | |
return function (world) { | |
alert(message); | |
var newWorld = world; | |
newWorld["alerted"] = "DONE"; | |
return [newWorld, null]; | |
}; | |
} | |
// IO Date | |
function dateIO (world) { | |
return [world, new Date()]; | |
} | |
// (Date -> IO ()) -> IO () | |
var doItWithDate = function(f) { | |
return bind(dateIO, f); | |
}; | |
// IO () | |
var main = doItWithDate(alertIO); | |
unsafePerformIO(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment