Created
November 26, 2011 13:23
-
-
Save KOBA789/1395662 to your computer and use it in GitHub Desktop.
きっとMonadic
This file contains hidden or 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
| var fs = require('fs'); | |
| function putStrLn (m) { | |
| return function (cb) { | |
| if (m) { | |
| m(function (str) { | |
| console.log(str); | |
| cb(); | |
| }); | |
| } else { | |
| console.log(str); | |
| cb(); | |
| } | |
| } | |
| } | |
| function wait(time) { | |
| return function (m) { | |
| return function (cb) { | |
| if (m) { | |
| m(function() { | |
| setTimeout(function () { | |
| cb(); | |
| }, time); | |
| }); | |
| } else { | |
| setTimeout(function () { | |
| cb(); | |
| }, time); | |
| } | |
| } | |
| } | |
| } | |
| function val (val) { | |
| return function (m) { | |
| return function (cb) { | |
| if (m) { | |
| m(function () { | |
| cb(val); | |
| }); | |
| } else { | |
| cb(val); | |
| } | |
| } | |
| } | |
| } | |
| function getClockTime (m) { | |
| return function (cb) { | |
| if (m) { | |
| m(function () { | |
| cb((new Date).toString()); | |
| }); | |
| } else { | |
| cb((new Date).toString()); | |
| } | |
| } | |
| } | |
| var noop = function () {}; | |
| var main = | |
| putStrLn( | |
| getClockTime( | |
| putStrLn( | |
| val('world')( | |
| wait(1000)( | |
| putStrLn( | |
| getClockTime( | |
| putStrLn( | |
| val('hello')() | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| main(noop); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment