Created
July 17, 2020 11:17
-
-
Save dmjio/5deb406a63e57b8aca2d68c2bd995100 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
newtype DL a = DL { unDL :: [a] -> [a] } | |
instance Show a => Show (DL a) where | |
show = show . toList | |
instance Semigroup (DL a) where | |
DL f <> DL g = DL (f <> g) | |
instance Monoid (DL a) where | |
mempty = DL mempty | |
instance Functor DL where | |
fmap = liftM | |
instance Foldable DL where | |
foldMap f g = foldMap f (toList g) | |
instance Applicative DL where | |
pure = return | |
(<*>) = ap | |
instance Monad DL where | |
return = \x -> DL $ \xs -> [x] | |
m >>= f = foldMap f m | |
concat :: [DL a] -> DL a | |
concat = mconcat | |
append :: DL a -> DL a -> DL a | |
append = (<>) | |
fromList :: [a] -> DL a | |
fromList = foldMap pure | |
toList :: DL a -> [a] | |
toList (DL f) = f mempty | |
singleton :: a -> DL a | |
singleton = pure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment