Commit e428b5b8 authored by David Feuer's avatar David Feuer Committed by Joachim Breitner

Add Data.List.uncons

Summary:
As discussed in
http://www.haskell.org/pipermail/libraries/2014-July/023314.html and
submitted at #9550.

Test Plan: Submit to phab, see what happens.

Reviewers: austin

Subscribers: simonmar, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D195

GHC Trac Issues: #9550
parent 1719c420
......@@ -24,6 +24,7 @@ module Data.List
, last
, tail
, init
, uncons
, null
, length
......
......@@ -21,7 +21,7 @@ module GHC.List (
-- [] (..), -- built-in syntax; can't be used in export list
map, (++), filter, concat,
head, last, tail, init, null, length, (!!),
head, last, tail, init, uncons, null, length, (!!),
foldl, scanl, scanl1, foldr, foldr1, scanr, scanr1,
iterate, repeat, replicate, cycle,
take, drop, splitAt, takeWhile, dropWhile, span, break,
......@@ -71,6 +71,13 @@ badHead = errorEmptyList "head"
head (augment g xs) = g (\x _ -> x) (head xs)
#-}
-- | Decompose a list into its head and tail. If the list is empty,
-- returns 'Nothing'. If the list is non-empty, returns @'Just' (x, xs)@,
-- where @x@ is the head of the list and @xs@ its tail.
uncons :: [a] -> Maybe (a, [a])
uncons [] = Nothing
uncons (x:xs) = Just (x, xs)
-- | Extract the elements after the head of a list, which must be non-empty.
tail :: [a] -> [a]
tail (_:xs) = xs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment