Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 1, 2015 11:14
Show Gist options
  • Save motokiee/ec1815e294c6e842468f to your computer and use it in GitHub Desktop.
Save motokiee/ec1815e294c6e842468f to your computer and use it in GitHub Desktop.
head' :: [a] -> a
head' [] = error "No Head"
head' (x:_) = x
head2' :: [a] -> a
head2' xs = case xs of [] -> error "No Head"
(x:_) -> x
describeList :: [a] -> String
describeList ls = "This list is" ++ case ls of [] -> " empty"
[x] -> " a singleton list."
xs -> " a longer list."
describeList2 :: [a] -> String
describeList2 ls = "The list is " ++ what ls
where what [] = "empty"
what [x] = "a singleton list."
what xs = " a longer list."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment