Last active
September 22, 2020 20:36
-
-
Save i-am-tom/c9f07fdbf80ca4773ae1c01959999591 to your computer and use it in GitHub Desktop.
Monoids in the category of thendofunctors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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