Ticket #1182: 0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_2010.patch
| File 0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_2010.patch, 2.1 KB (added by michalt, 2 years ago) |
|---|
-
Data/List.hs
From 5f2cd1328b3ae36bdf4750a66df39265b747bd34 Mon Sep 17 00:00:00 2001 From: Michal Terepeta <michal.terepeta@gmail.com> Date: Mon, 20 Jun 2011 21:06:20 +0200 Subject: [PATCH] Make splitAt conform to Haskell 98/2010 (fixes #1182). --- Data/List.hs | 2 +- Prelude.hs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Data/List.hs b/Data/List.hs index 8258663..78f633f 100644
a b 181 181 , genericReplicate -- :: (Integral a) => a -> b -> [b] 182 182 183 183 ) where 184 import "base" Data.List 184 import "base" Data.List hiding ( splitAt ) -
Prelude.hs
diff --git a/Prelude.hs b/Prelude.hs index 9be6ccf..72e53d2 100644
a b 137 137 import "base" Control.Monad 138 138 import "base" System.IO 139 139 import "base" System.IO.Error (IOError, ioError, userError) 140 import "base" Data.List 140 import "base" Data.List hiding ( splitAt ) 141 141 import "base" Data.Either 142 142 import "base" Data.Maybe 143 143 import "base" Data.Tuple … … 216 216 gcd x y = GHC.Real.gcd x y 217 217 #endif 218 218 219 #ifndef __HUGS__ 220 -- The GHC's version of 'splitAt' is too strict in 'n' compared to 221 -- Haskell98/2010 version. Ticket #1182. 222 223 -- | 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of 224 -- length @n@ and second element is the remainder of the list: 225 -- 226 -- > splitAt 6 "Hello World!" == ("Hello ","World!") 227 -- > splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5]) 228 -- > splitAt 1 [1,2,3] == ([1],[2,3]) 229 -- > splitAt 3 [1,2,3] == ([1,2,3],[]) 230 -- > splitAt 4 [1,2,3] == ([1,2,3],[]) 231 -- > splitAt 0 [1,2,3] == ([],[1,2,3]) 232 -- > splitAt (-1) [1,2,3] == ([],[1,2,3]) 233 -- 234 -- It is equivalent to @('take' n xs, 'drop' n xs)@. 235 -- 'splitAt' is an instance of the more general 'Data.List.genericSplitAt', 236 -- in which @n@ may be of any integral type. 237 splitAt :: Int -> [a] -> ([a],[a]) 238 splitAt n xs = (take n xs, drop n xs) 239 #endif
