Bryan O'Sullivan avatar Bryan O'Sullivan committed 2142c8b

Fix type of splitAt

Comments (0)

Files changed (2)

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'')

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.