@@ -264,4 +264,66 @@ module Math where
266 foreign import math :: Math
266 foreign import math :: Math
270+ foreign import data Eff :: # ! -> * -> *
272+ foreign import retEff "function retEff(a) { return function() { return a; }; }" :: forall e a. a -> Eff e a
274+ foreign import bindEff "function bindEff(a) { return function(f) { return function() { return f(a())(); }; }; }" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
276+ type Pure a = forall e. Eff e a
278+ foreign import runPure :: forall a. Pure a -> a
280+ eff = { ret: retEff, bind: bindEff }
286+ foreign import data Error :: * -> !
288+ foreign import throwError "function throwError(e) { return function() { throw e; }; }" :: forall e r. e -> Eff (err :: Error e | r) {}
290+ foreign import catchError "function catchError(c) { return function(t) { return function() { try { return t(); } catch(e) { return c(e)(); } }; }; }" :: forall e r a. (e -> Eff r a) -> Eff (err :: Error e | r) a -> Eff r a
296+ foreign import data Ref :: !
298+ foreign import data IORef :: * -> *
300+ foreign import newIORef :: forall s r. a -> Eff (ref :: Ref | r) (IORef s)
302+ foreign import readIORef :: forall s r. IORef s -> Eff (ref :: Ref | r) s
304+ foreign import writeIORef :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
310+ foreign import data Trace :: !
312+ foreign import trace "function trace(s) { return function() { console.log(s); return {}; }; }" :: forall r. String -> Eff (trace :: Trace | r) {}
318+ foreign import data ST :: * -> !
320+ foreign import data STRef :: * -> * -> *
322+ foreign import newSTRef :: forall a h r. a -> Eff (st :: ST h | r) (STRef h a)
324+ foreign import readSTRef :: forall a h r. STRef h a -> Eff (st :: ST h | r) a
326+ foreign import modifySTRef :: forall a h r. (a -> a) -> STRef h a -> Eff (st :: ST h | r) {}
328+ foreign import runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a