Last active
October 26, 2015 03:24
-
-
Save codebje/775825fa87325f8346e4 to your computer and use it in GitHub Desktop.
Monoid with zero element
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
module Mzero where | |
import Data.Monoid | |
class Monoid a => MonoidZ a where | |
zero :: a | |
mconcat :: (Eq a) => [a] -> a | |
mconcat = go | |
where | |
go [] = mempty | |
go (x:xs) | x == zero = zero | |
| otherwise = x `mappend` go xs | |
instance Num a => MonoidZ (Product a) where | |
zero = 0 | |
instance MonoidZ All where | |
zero = All False | |
instance MonoidZ Any where | |
zero = Any True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment