Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created August 19, 2015 11:52
Show Gist options
  • Save shigemk2/b200e0c509348627a4c5 to your computer and use it in GitHub Desktop.
Save shigemk2/b200e0c509348627a4c5 to your computer and use it in GitHub Desktop.
import Data.Monoid
-- getProductなどでモノイドの中身の値を取り出す
main = do
-- product
print $ Product 3 `mappend` Product 9
print $ getProduct $ Product 3 `mappend` Product 9
print $ getProduct $ Product 3 `mappend` mempty
print $ getProduct $ Product 3 `mappend` Product 4 `mappend` Product 2
print $ getProduct $ Product 3 `mappend` (Product 4 `mappend` Product 2)
print $ getProduct . mconcat . map Product $ [3,4,2]
-- sum
print $ Sum 2 `mappend` Sum 9
print $ getSum $ Sum 2 `mappend` Sum 9
print $ getSum $ Sum 2 `mappend` Sum 9 `mappend` Sum 9
print $ getSum $ Sum 2 `mappend` (Sum 9 `mappend` Sum 9)
print $ getSum $ mempty `mappend` Sum 3
print $ getSum . mconcat . map Sum $ [1,2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment