module Pandora.Pattern.Functor.Bindable (Bindable (..)) where
import Pandora.Core.Functor (type (:.), type (:=))
import Pandora.Core.Morphism ((%), identity)
import Pandora.Pattern.Functor.Covariant (Covariant)
infixl 1 >>=
infixr 1 =<<, <=<, >=>
class Covariant t => Bindable t where
{-# MINIMAL (>>=) #-}
(>>=) :: t a -> (a -> t b) -> t b
(=<<) :: (a -> t b) -> t a -> t b
(=<<) = (%) (>>=)
bind :: (a -> t b) -> t a -> t b
bind f t = t >>= f
join :: t :. t := a -> t a
join t = t >>= identity
(>=>) :: (a -> t b) -> (b -> t c) -> (a -> t c)
f >=> g = \x -> f x >>= g
(<=<) :: (b -> t c) -> (a -> t b) -> (a -> t c)
(<=<) = (%) (>=>)
instance Bindable ((->) e) where
f >>= g = \x -> g (f x) x