Monadify evented code OR: how to put synchronicity back in asynchronous code.
Here i describe how to use CoffeeScript in order to port the "synchronous" programming style to the evented, turn based Model used by node.js
(a -> Maybe b) -> Maybe b Nothing >>= _ = Nothing (Just x) >>= f = f x return :: a -> Maybe a return x = Just x add :: Maybe Int -> Maybe Int -> Maybe Int add mx my = mx >>= (\x -> my >>= (\y -> return (x + y)))
(a -> Maybe b) -> Maybe b Nothing >>= _ = Nothing (Just x) >>= f = f x return :: a -> Maybe a return x = Just x add :: Maybe Int -> Maybe Int -> Maybe Int add mx my = do x <- mx y <- my return (x + y)
masked values – type<a> M<a> • The >>= operator extracts a from M<a> – operator<a,b> M<a> >>= (a -> M<b>) -> M<b> • The >>= operator may delay the execution of the function • And that‘s it.
need the foundation for this • Javascript has – No operator overloading – No >>= operator – Is dynamically typed • Our requirements are: – Something thats to use like a monad – Some replacement for the >>= operator