Created
November 11, 2017 22:07
-
-
Save buggymcbugfix/ec431b0291031482ffd00136caa1ffde 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.Monoid | |
data List a = List | List a :• a | |
xs • x = xs :• x | |
infixl • | |
instance Show a => Show (List a) where | |
show List = "List" | |
show (xs :• x) = show xs ++ " •" ++ show x | |
ex1 = List • 1 • 2 • 3 • 4 • 5 | |
ex2 = List | |
• "Eggs" | |
• "Milk" | |
• "Flour" | |
• "Cabbage" | |
instance Monoid (List a) where | |
mempty = List | |
mappend List ys = ys | |
mappend xs List = xs | |
mappend xs (ys :• y) = mappend xs ys :• y | |
instance Functor List where | |
fmap f List = List | |
fmap f (xs :• x) = (fmap f xs) • f x | |
ex3 = (++ "!") <$> ex2 <> fmap show ex1 | |
-- List •"Eggs!" •"Milk!" •"Flour!" •"Cabbage!" •"1!" •"2!" •"3!" •"4!" •"5!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment