Ticket #1182: 0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_98.patch
| File 0001-Make-splitAt-conform-to-Haskell-98-2010-fixes-1182_98.patch, 2.1 KB (added by michalt, 2 years ago) |
|---|
-
List.hs
From 09db8771c10fc7a41ea7a73fc7fb44a7c4d3cbc7 Mon Sep 17 00:00:00 2001 From: Michal Terepeta <michal.terepeta@gmail.com> Date: Mon, 20 Jun 2011 21:09:01 +0200 Subject: [PATCH] Make splitAt conform to Haskell 98/2010 (fixes #1182). --- List.hs | 2 +- Prelude.hs | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/List.hs b/List.hs index ca3b51f..147e283 100644
a b 26 26 zip, zip3, zipWith, zipWith3, unzip, unzip3 27 27 ) where 28 28 29 import Data.List hiding (foldl' )29 import Data.List hiding (foldl', splitAt) -
Prelude.hs
diff --git a/Prelude.hs b/Prelude.hs index 44342a0..75a35b4 100644
a b 138 138 import "base" Control.Monad 139 139 import "base" System.IO 140 140 import "base" System.IO.Error (IOError, ioError, userError) 141 import "base" Data.List 141 import "base" Data.List hiding ( splitAt ) 142 142 import "base" Data.Either 143 143 import "base" Data.Maybe 144 144 import "base" Data.Tuple … … 216 216 gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined" 217 217 gcd x y = GHC.Real.gcd x y 218 218 #endif 219 220 #ifndef __HUGS__ 221 -- The GHC's version of 'splitAt' is too strict in 'n' compared to 222 -- Haskell98/2010 version. Ticket #1182. 223 224 -- | 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of 225 -- length @n@ and second element is the remainder of the list: 226 -- 227 -- > splitAt 6 "Hello World!" == ("Hello ","World!") 228 -- > splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5]) 229 -- > splitAt 1 [1,2,3] == ([1],[2,3]) 230 -- > splitAt 3 [1,2,3] == ([1,2,3],[]) 231 -- > splitAt 4 [1,2,3] == ([1,2,3],[]) 232 -- > splitAt 0 [1,2,3] == ([],[1,2,3]) 233 -- > splitAt (-1) [1,2,3] == ([],[1,2,3]) 234 -- 235 -- It is equivalent to @('take' n xs, 'drop' n xs)@. 236 -- 'splitAt' is an instance of the more general 'Data.List.genericSplitAt', 237 -- in which @n@ may be of any integral type. 238 splitAt :: Int -> [a] -> ([a],[a]) 239 splitAt n xs = (take n xs, drop n xs) 240 #endif
