Skip to content

Instantly share code, notes, and snippets.

@hiratara
Created November 8, 2012 12:58
Show Gist options
  • Save hiratara/4038651 to your computer and use it in GitHub Desktop.
Save hiratara/4038651 to your computer and use it in GitHub Desktop.
Kleisli endo-morphisms are an instance of Monoid.
{-# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment