Created
November 8, 2012 12:58
-
-
Save hiratara/4038651 to your computer and use it in GitHub Desktop.
Kleisli endo-morphisms are an instance of Monoid.
This file contains hidden or 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 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