Skip to content

Instantly share code, notes, and snippets.

@dawehner
Created March 31, 2017 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawehner/0f482284225f4a65d53c8f4388fe8bfc to your computer and use it in GitHub Desktop.
Save dawehner/0f482284225f4a65d53c8f4388fe8bfc to your computer and use it in GitHub Desktop.
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