From: Reino Ruusu Date: Fri, 22 Mar 2019 12:51:03 +0000 (+0200) Subject: Added effectful Kleisli composition to Prelude. X-Git-Tag: v1.43.0~136^2~171^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=bd78deb4759a49ed84200b95fddc9569438512f7 Added effectful Kleisli composition to Prelude. gitlab #280 Change-Id: If7a721ef2508b84490304a8353b31e8de9f25d27 --- 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