public
Created

Kleisli endo-morphisms are an instance of Monoid.

  • Download Gist
main.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
{-# LANGUAGE FlexibleInstances, OverlappingInstances #-}
module Main where
import Data.Monoid
import Control.Monad
 
instance Monad m => Monoid (a -> m a) where
mempty = return
mappend = (>=>)
 
main :: IO ()
main = do
let m = \x -> [x * 2, x * 3]
let m' = \x -> [x + 1, x, x - 1]
let mm' = m `mappend` mempty `mappend` m'
print $ mm' 2

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.