Skip to content

Instantly share code, notes, and snippets.

@bradparker
Created April 11, 2016 09:26
Show Gist options
  • Save bradparker/3b88f13d2406b91fc72c750dcd1b1b9b to your computer and use it in GitHub Desktop.
Save bradparker/3b88f13d2406b91fc72c750dcd1b1b9b to your computer and use it in GitHub Desktop.
Cons!
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