Last active
August 29, 2015 14:21
-
-
Save fritz0705/2438f7268bdb6aabca29 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.Foldable (fold) | |
import Data.Monoid (Endo(Endo, appEndo)) | |
-- | @replicateEndo n f@ replicates n times an endomorphism f and folds them using | |
-- function composition to an endomorphism @a -> a@. | |
-- | |
-- Propositions: | |
-- > replicateEndo _ id == id | |
-- > replicateEndo _ (const x) == const x | |
-- > replicateEndo 0 _ == id | |
replicateEndo :: Int -> (a -> a) -> a -> a | |
replicateEndo n = appEndo.fold.replicate n.Endo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment