[project @ 1999-02-02 17:37:39 by simonm]
[ghc-hetmet.git] / ghc / lib / std / PrelList.lhs
index 8773bf2..5e99d90 100644 (file)
@@ -24,7 +24,7 @@ module PrelList (
 
    -- non-standard, but hidden when creating the Prelude
    -- export list.
-   takeUInt
+   takeUInt_append
 
  ) where
 
@@ -205,23 +205,35 @@ splitAt _     _           =  errorNegativeIdx "splitAt"
 
 #else /* hack away */
 take   :: Int -> [b] -> [b]
-take (I# n#) xs = takeUInt n# xs []
+take (I# n#) xs = takeUInt n# xs
 
 -- The general code for take, below, checks n <= maxInt
 -- No need to check for maxInt overflow when specialised
 -- at type Int or Int# since the Int must be <= maxInt
 
-takeUInt :: Int# -> [b] -> [b] -> [b]
-takeUInt n xs rs
-  | n >=# 0#  =  take_unsafe_UInt n xs rs
+takeUInt :: Int# -> [b] -> [b]
+takeUInt n xs
+  | n >=# 0#  =  take_unsafe_UInt n xs
   | otherwise =  errorNegativeIdx "take"
 
-take_unsafe_UInt :: Int# -> [b] -> [b] -> [b]
-take_unsafe_UInt 0#  _ rs  = rs
-take_unsafe_UInt m  ls rs  =
+take_unsafe_UInt :: Int# -> [b] -> [b]
+take_unsafe_UInt 0#  _  = []
+take_unsafe_UInt m   ls =
+  case ls of
+    []     -> []
+    (x:xs) -> x : take_unsafe_UInt (m -# 1#) xs
+
+takeUInt_append :: Int# -> [b] -> [b] -> [b]
+takeUInt_append n xs rs
+  | n >=# 0#  =  take_unsafe_UInt_append n xs rs
+  | otherwise =  errorNegativeIdx "take"
+
+take_unsafe_UInt_append        :: Int# -> [b] -> [b] -> [b]
+take_unsafe_UInt_append        0#  _ rs  = rs
+take_unsafe_UInt_append        m  ls rs  =
   case ls of
     []     -> rs
-    (x:xs) -> x : take_unsafe_UInt (m -# 1#) xs rs
+    (x:xs) -> x : take_unsafe_UInt_append (m -# 1#) xs rs
 
 drop           :: Int -> [b] -> [b]
 drop (I# n#) ls