Created
August 19, 2015 11:52
-
-
Save shigemk2/b200e0c509348627a4c5 to your computer and use it in GitHub Desktop.
This file contains 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
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