commit 0d9bbd357bd4c38e46546e7be0802e51ee3b6b42
parent b28eb21d7ba63b697df755ad4893b259986970b7
Author: Robert Russell <robert@rr3.xyz>
Date: Thu, 10 Sep 2026 11:48:28 -0700
Algebra.Category: RebindableSyntax
Diffstat:
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/Lude/Algebra/Category/Monad.hs b/src/Lude/Algebra/Category/Monad.hs
@@ -3,9 +3,15 @@
module Lude.Algebra.Category.Monad (
Monadic (..),
MonadicOn,
+ --
+ (>>=),
+ (=<<),
+ (>>),
+ (<<),
) where
import Lude.Algebra.Category.Core
+import Lude.Function (const, flip)
import Lude.Haskell
-- TODO: Make applicative/monoidal functors a superclass.
@@ -14,7 +20,8 @@ import Lude.Haskell
--------------------------------------------------------------------------------
--- infixl 1 >>=, >>
+infixl 1 >>=, >>
+infixr 1 =<<, <<
--------------------------------------------------------------------------------
@@ -46,5 +53,14 @@ instance Monadic ((->) r) where
join mm = \c -> mm c c
bind k m = \c -> k (m c) c
--- (>>=) :: forall f a b. (MonadicOn Function f) => f a -> (a -> f b) -> f b
--- (>>=) = ()
+(>>=) :: forall f a b. (MonadicOn Function f) => f a -> (a -> f b) -> f b
+(>>=) = flip bind
+
+(=<<) :: forall f a b. (MonadicOn Function f) => (a -> f b) -> f a -> f b
+(=<<) = bind
+
+(>>) :: forall f a b. (MonadicOn Function f) => f a -> f b -> f b
+fa >> fb = bind (const fb) fa
+
+(<<) :: forall f a b. (MonadicOn Function f) => f a -> f b -> f a
+fa << fb = bind (\a -> fb >> pure a) fa