Skip to content

Instantly share code, notes, and snippets.

@i-am-tom

i-am-tom/Main.hs

Last active Sep 22, 2020
Embed
What would you like to do?
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