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

Patch for haskell98.

  • List.hs

    From 09db8771c10fc7a41ea7a73fc7fb44a7c4d3cbc7 Mon Sep 17 00:00:00 2001
    From: Michal Terepeta <[email protected]>
    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 module List ( 
    2626    zip, zip3, zipWith, zipWith3, unzip, unzip3
    2727  ) where
    2828
    29 import Data.List hiding (foldl')
     29import Data.List hiding (foldl', splitAt)
  • Prelude.hs

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