[commit: ghc] master: Add Data.List.uncons (e428b5b)
git at git.haskell.org
git at git.haskell.org
Thu Sep 4 08:35:35 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/e428b5b8cc1448dcff7d7cdcbeb738eb0bea102f/ghc
>---------------------------------------------------------------
commit e428b5b8cc1448dcff7d7cdcbeb738eb0bea102f
Author: David Feuer <david.feuer at gmail.com>
Date: Thu Sep 4 08:04:12 2014 +0200
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
>---------------------------------------------------------------
e428b5b8cc1448dcff7d7cdcbeb738eb0bea102f
libraries/base/Data/List.hs | 1 +
libraries/base/GHC/List.lhs | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/libraries/base/Data/List.hs b/libraries/base/Data/List.hs
index 2cd9a3b..f813741 100644
--- a/libraries/base/Data/List.hs
+++ b/libraries/base/Data/List.hs
@@ -24,6 +24,7 @@ module Data.List
, last
, tail
, init
+ , uncons
, null
, length
diff --git a/libraries/base/GHC/List.lhs b/libraries/base/GHC/List.lhs
index bcc5fea..4fcb54a 100644
--- a/libraries/base/GHC/List.lhs
+++ b/libraries/base/GHC/List.lhs
@@ -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
More information about the ghc-commits
mailing list