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, 4 years ago)

Patch for haskell2010.

  • Data/List.hs

    From 5f2cd1328b3ae36bdf4750a66df39265b747bd34 Mon Sep 17 00:00:00 2001
    From: Michal Terepeta <[email protected]>
    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 module Data.List ( 
    181181   , genericReplicate  -- :: (Integral a) => a -> b -> [b]
    182182
    183183  ) where
    184 import "base" Data.List
     184import "base" Data.List hiding ( splitAt )
  • Prelude.hs

    diff --git a/Prelude.hs b/Prelude.hs
    index 9be6ccf..72e53d2 100644
    a b import qualified "base" Control.Exception.Base as New (catch) 
    137137import "base" Control.Monad
    138138import "base" System.IO
    139139import "base" System.IO.Error (IOError, ioError, userError)
    140 import "base" Data.List
     140import "base" Data.List hiding ( splitAt )
    141141import "base" Data.Either
    142142import "base" Data.Maybe
    143143import "base" Data.Tuple
    gcd 0 0 = error "Prelude.gcd: gcd 0 0 is undefined" 
    216216gcd x y         = GHC.Real.gcd x y
    217217#endif
    218218
     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.
     237splitAt                :: Int -> [a] -> ([a],[a])
     238splitAt n xs           =  (take n xs, drop n xs)
     239#endif