Created
April 11, 2016 09:26
-
-
Save bradparker/3b88f13d2406b91fc72c750dcd1b1b9b to your computer and use it in GitHub Desktop.
Cons!
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
data List a = | |
Empty | | |
Cons a (List a) | |
deriving ( | |
Eq, | |
Ord | |
) | |
-- Type classes are pretyy cool | |
instance (Show a) => Show (List a) where | |
show Empty = "()" | |
show (Cons x xs) = "(" ++ (show x) ++ " " ++ (show xs) ++ ")" | |
car :: List a -> a | |
car Empty = error "car called on empty List." | |
car (Cons h _) = h | |
cdr :: List a -> List a | |
cdr Empty = error "cdr called on empty List." | |
cdr (Cons _ t) = t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment