From bd78deb4759a49ed84200b95fddc9569438512f7 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Fri, 22 Mar 2019 14:51:03 +0200 Subject: [PATCH] Added effectful Kleisli composition to Prelude. gitlab #280 Change-Id: If7a721ef2508b84490304a8353b31e8de9f25d27 --- bundles/org.simantics.scl.runtime/scl/Prelude.md | 5 ++++- bundles/org.simantics.scl.runtime/scl/Prelude.scl | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.md b/bundles/org.simantics.scl.runtime/scl/Prelude.md index df91f29d1..531a63587 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.md +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.md @@ -81,13 +81,16 @@ ## Monads ::class[Monad] -::value[>>] +::value[>>, >=>] ::class[FunctorM] ::value[repeatForever] ::class[MonadZero] ::value[guard] ::class[MonadPlus, MonadOr] ::value[ignoreM] +::class[MonadE] +::value[compE] +::class[MonadZeroE] # Side-effects diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index e92603bec..f98325109 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1096,6 +1096,7 @@ class (FunctorE f) => FunctorM f where /// MonadE /// class (FunctorE m, Monad m) => MonadE m where + "An effectful version of the bind operator `(>>=)`" bindE :: m a -> (a -> m b) -> m b instance MonadE Maybe where @@ -1109,6 +1110,11 @@ instance MonadE (Either a) where instance MonadE [] where bindE l f = concatMap f l +@inline +"An effectful version of the Kleisli composition operator `(>=>)`" +compE :: MonadE m => (a -> m b) -> (b -> m c) -> a -> m c +compE f g x = (f x) `bindE` g + /// MZeroE /// class (MonadE m, MonadZero m) => MonadZeroE m where -- 2.47.1