Created
March 31, 2017 14:11
-
-
Save dawehner/0f482284225f4a65d53c8f4388fe8bfc 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
data List a = | |
Nil | |
| Cons a (List a) | |
deriving (Eq, Show) | |
instance Monoid (List a) where | |
mempty :: List a | |
mempty = Nil | |
mappend :: List a -> List a -> List a | |
mappend xs Nil = xs | |
mappend Nil ys = ys | |
mappend (Cons x xs) ys = Cons x (xs `mappend` ys) | |
instance Functor List where | |
fmap :: (a -> b) -> List a -> List b | |
fmap _ Nil = Nil | |
fmap f (Cons x xs) = Cons (f x) (fmap f xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment