Last active
January 1, 2016 16:49
-
-
Save MgaMPKAy/8172960 to your computer and use it in GitHub Desktop.
Lists form a free 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
import Data.Monoid | |
h x = [x] | |
{-- | |
h | |
A ----->[A] | |
\ | | |
\ | | |
\ | | |
f \ | f# | |
\ | | |
\ | | |
\| | |
B | |
For every monoid B and f :: A -> B, there is a unique homorphism f# from the monoid of list to B. | |
Which is the correct proof: ftofsharp or fold ? | |
--} | |
ftofsharp :: Monoid b -- monoid (implictly determined by f) | |
=> (a -> b) -- f | |
-> ([a] -> b) -- f# | |
ftofsharp f = f . head | |
fold :: Monoid b => (a -> b) -> ([a] -> b) | |
fold f [] = mempty | |
fold f (x:xs) = mappend (f x) (fold f xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment