Skip to content

Instantly share code, notes, and snippets.

@khibino
Last active December 17, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khibino/5635382 to your computer and use it in GitHub Desktop.
Save khibino/5635382 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeOperators #-}
module Monoid where
import Data.Monoid (Monoid, Sum, Product)
import qualified Data.Monoid as M
import Control.Category
class Category (-->) => CategoricalMonoid (-->) m where
mempty :: m
(<>) :: m --> (m --> m)
class (CategoricalMonoid (-->) m, CategoricalMonoid (-->) n)
=> MonoidHomomorphism (-->) f m n where
mapMH :: f (m --> m --> m) (n --> n --> n)
instance Monoid m => CategoricalMonoid (->) m where
mempty = M.mempty
(<>) = (M.<>)
newtype Pow a b = Pow ((a -> (a -> a)) ->
(b -> (b -> b)))
instance Integral a => MonoidHomomorphism (->) Pow (Sum a) (Product a) where
mapMH = Pow $ const (<>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment