Commits

Bryan O'Sullivan committed 2142c8b

Fix type of splitAt

  • Participants
  • Parent commits d46f575

Comments (0)

Files changed (2)

File Data/Text/Lazy.hs

 -- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
 -- prefix of @t@ of length @n@, and whose second is the remainder of
 -- the string. It is equivalent to @('take' n t, 'drop' n t)@.
-splitAt :: Int -> Text -> (Text, Text)
+splitAt :: Int64 -> Text -> (Text, Text)
 splitAt = loop
   where loop _ Empty      = (empty, empty)
         loop n t | n <= 0 = (empty, t)
         loop n (Chunk t ts)
-             | n < len   = let (ts',ts'') = T.splitAt n t
+             | n < len   = let (ts',ts'') = T.splitAt (fromIntegral n) t
                            in (Chunk ts' Empty, Chunk ts'' Empty)
              | otherwise = let (ts',ts'') = loop (n - len) ts
                            in (Chunk t ts', ts'')

File tests/Properties.hs

 instance Target TL.Text where
     packT    = TL.pack
     unpackT  = TL.unpack
-    splitAtT = TL.splitAt
+    splitAtT = TL.splitAt . fromIntegral
 
 -- Do two functions give the same answer?
 eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
 prop_T_dropWhile p     = L.dropWhile p `eqP` (unpackT . T.dropWhile p)
 prop_TL_dropWhile p    = L.dropWhile p `eqP` (unpackT . S.dropWhile p)
 prop_T_splitAt n       = L.splitAt n   `eqP` (unpack2 . T.splitAt n)
-prop_TL_splitAt n      = L.splitAt n   `eqP` (unpack2 . TL.splitAt n)
+prop_TL_splitAt n      = L.splitAt n   `eqP` (unpack2 . TL.splitAt (fromIntegral n))
 prop_T_span p          = L.span p      `eqP` (unpack2 . T.span p)
 prop_T_break p         = L.break p     `eqP` (unpack2 . T.break p)
 prop_T_group           = L.group       `eqP` (map unpackT . T.group)