]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
New type class MonadE and corresponding monad syntax with edo keyword
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index 05b5f2785675c6da8738e28287a465b6f8c22d4f..907d6e00d74084dfc12dddedd205448624ecc2a8 100644 (file)
@@ -1088,6 +1088,22 @@ class (Functor f) => FunctorM f where
     sequence :: Monad m => f (m a) -> m (f a) 
     mapM f l = sequence (fmap f l)
 
+/// MonadE ///
+
+class (FunctorE m, Monad m) => MonadE m where
+    bindE :: m a -> (a -> <e> m b) -> <e> m b
+
+instance MonadE Maybe where
+    bindE Nothing  _ = Nothing
+    bindE (Just v) f = f v
+    
+instance MonadE (Either a) where
+    bindE (Left v)  _ = Left v
+    bindE (Right v) f = f v
+
+instance MonadE [] where
+    bindE l f = concatMap f l
+    
 /// Category ///
 
 "Identity function."