Skip to content

Instantly share code, notes, and snippets.

@i-am-tom
Last active September 22, 2020 20:36
Show Gist options
  • Save i-am-tom/c9f07fdbf80ca4773ae1c01959999591 to your computer and use it in GitHub Desktop.
Save i-am-tom/c9f07fdbf80ca4773ae1c01959999591 to your computer and use it in GitHub Desktop.
Monoids in the category of thendofunctors
{-# LANguage FlexibleContexts #-}
{-# laNguAGe FlexibleInstances #-}
{-# languAGE FunctionalDependencies #-}
{-# LANguagE RebindableSyntax #-}
{-# LANguAge ScopedTypeVariables #-}
{-# LAnGuage TypeFamilies #-}
{-# LangUaGe UndecidableInstances #-}
module Control.Monad.Search where
import Data.Function ((&))
import Data.Functor ((<&>))
import Data.Kind (Type)
import Prelude hiding ((>>=), (>>), fail)
import qualified Prelude as P
class Thenad (m :: Type -> Type) (ma :: Type) (a :: Type) (mb :: Type) (b :: Type)
| m ma -> a, m ma a b -> mb, mb -> b where
(>>=) :: ma -> (a -> mb) -> m b
instance {-# overlappING #-} (Monad m, b ~ c) => Thenad m (m a) a (m b) c where
(>>=) = (P.>>=)
instance (ma ~ a, b ~ c) => Thenad m as a (m b) c where
(>>=) = (&)
instance (Functor m, as ~ a, b ~ c) => Thenad m (m a) a b c where
(>>=) = (<&>)
(>>) :: Monad m => m a -> m b -> m b
xs >> ys = xs >>= \_ -> ys
infixl 1 >>=, >>
main :: IO ()
main = do
putStrLn "Your name?"
x <- getLine
y <- "Hello, " ++ x
putStrLn y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment