Created
May 19, 2022 19:18
-
-
Save phadej/2a185790c4b151c6f868dc92ffb5aaf9 to your computer and use it in GitHub Desktop.
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.Coerce | |
import Data.Monoid | |
-- This combinator is based on ala' from Conor McBride's work on Epigram. | |
alaf :: (Coercible n o, Coercible n' o') | |
=> (o -> n) -> ((a -> n) -> b -> n') -> (a -> o) -> b -> o' | |
alaf _ = coerce | |
myfoldl :: Foldable t => (b -> a -> b) -> b -> t a -> b | |
myfoldl f z xs = alaf (Dual . Endo) foldMap (flip f) xs z | |
-- | |
-- >>> myreverse "keep it simple" | |
-- "elpmis ti peek" | |
-- | |
myreverse :: [a] -> [a] | |
myreverse = myfoldl (flip (:)) [] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment