on master help sign in
Fix type of splitAt
919bf33Bryan O'Sullivan
Data/Text/Lazy.hs+2−2
@@ -577,12 +577,12 @@ dropWhile p t0 = dropWhile' t0
577-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
577-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a
578-- prefix of @t@ of length @n@, and whose second is the remainder of
578-- prefix of @t@ of length @n@, and whose second is the remainder of
579-- the string. It is equivalent to @('take' n t, 'drop' n t)@.
579-- the string. It is equivalent to @('take' n t, 'drop' n t)@.
580−splitAt :: Int -> Text -> (Text, Text)
580+splitAt :: Int64 -> Text -> (Text, Text)
581splitAt = loop
581splitAt = loop
582 where loop _ Empty = (empty, empty)
582 where loop _ Empty = (empty, empty)
583 loop n t | n <= 0 = (empty, t)
583 loop n t | n <= 0 = (empty, t)
584 loop n (Chunk t ts)
584 loop n (Chunk t ts)
585− | n < len = let (ts',ts'') = T.splitAt n t
585+ | n < len = let (ts',ts'') = T.splitAt (fromIntegral n) t
586 in (Chunk ts' Empty, Chunk ts'' Empty)
586 in (Chunk ts' Empty, Chunk ts'' Empty)
587 | otherwise = let (ts',ts'') = loop (n - len) ts
587 | otherwise = let (ts',ts'') = loop (n - len) ts
588 in (Chunk t ts', ts'')
588 in (Chunk t ts', ts'')
tests/Properties.hs+2−2
@@ -69,7 +69,7 @@ instance Target T.Text where
69instance Target TL.Text where
69instance Target TL.Text where
70 packT = TL.pack
70 packT = TL.pack
71 unpackT = TL.unpack
71 unpackT = TL.unpack
72− splitAtT = TL.splitAt
72+ splitAtT = TL.splitAt . fromIntegral
73
73
74-- Do two functions give the same answer?
74-- Do two functions give the same answer?
75eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
75eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
@@ -228,7 +228,7 @@ prop_S_dropWhile p = L.dropWhile p `eqP` (unpackT . S.dropWhile p)
228prop_T_dropWhile p = L.dropWhile p `eqP` (unpackT . T.dropWhile p)
228prop_T_dropWhile p = L.dropWhile p `eqP` (unpackT . T.dropWhile p)
229prop_TL_dropWhile p = L.dropWhile p `eqP` (unpackT . S.dropWhile p)
229prop_TL_dropWhile p = L.dropWhile p `eqP` (unpackT . S.dropWhile p)
230prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
230prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
231−prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt n)
231+prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
232prop_T_span p = L.span p `eqP` (unpack2 . T.span p)
232prop_T_span p = L.span p `eqP` (unpack2 . T.span p)
233prop_T_break p = L.break p `eqP` (unpack2 . T.break p)
233prop_T_break p = L.break p `eqP` (unpack2 . T.break p)
234prop_T_group = L.group `eqP` (map unpackT . T.group)
234prop_T_group = L.group `eqP` (map unpackT . T.group)