1

I am new to haskell, and the code below

import Data.Attoparsec.Text.Lazy
import qualified Data.Text.Lazy as T

toEol :: Parser T.Text
toEol = takeTill isEndOfLine

produces the following error message:

Couldn't match type `Data.Text.Internal.Text' with `TL.Text'
Expected type: Parser TL.Text
Actual type: Parser Data.Text.Internal.Text
In the return type of a call of `takeTill'
In the expression: takeTill isEndOfLine
In an equation for `cell':
    cell = takeTill isEndOfLine

Where does the type Data.Text.Internal.Text come from? Importing Data.Text instead of Data.Text.Lazy seems to solve the issue.

Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
dri
  • 11
  • 2
  • 1
    See the documentation for the [`Data.Text.Internal`](http://hackage.haskell.org/package/text-1.0.0.0/docs/Data-Text-Internal.html) module. The strict `Text` type `Data.Text.Text` [is actually a re-export of `Data.Text.Internal.Text`](http://hackage.haskell.org/package/text-1.0.0.0/docs/src/Data-Text.html). – Mikhail Glushenkov Dec 09 '13 at 00:26
  • The problem with your code is that `takeTill` returns a parser for strict `Text`, but your type signature signature says that it's a parser for lazy `Text`. That's why changing the import line solves the issue. – Mikhail Glushenkov Dec 09 '13 at 00:34
  • @MikhailGlushenkov- I agree with everything you said, but find it odd that attoparsec is exporting the non-lazy version of takeTill when he has only imported Data.Attoparsec.Text.Lazy.... Is this a bug? Looking in the documentation there doesn't even seem to be a lazy version of takeTill (which I accept, but why then export the obviously wrong one). He can convert using fromStrict, but that kind of ruins the whole point of using lazy :) – jamshidh Dec 09 '13 at 00:40
  • @jamshidh I encourage you to file a bug report on the attoparsec bug tracker. It seems like a mistake to me, and if it's not a bug, it shouldn't take long for the library authors to set you straight. – Daniel Wagner Dec 09 '13 at 04:17
  • From the documentation of `Data.Attoparsec.Text`: "Attoparsec is specialised to deal only with strict Text input. Efficiency concerns rule out both lists and lazy text. The usual use for lazy text would be to allow consumption of very large input without a large footprint. For this need, Attoparsec's incremental input provides an excellent substitute, with much more control over when input takes place. If you must use lazy text, see the Lazy module, which feeds lazy chunks to a regular parser." So I don't think it's a bug. – kosmikus Dec 09 '13 at 08:28
  • @kosimus The documentation for `Data.Attoparsec.Text.Lazy` reads :"This is essentially the same code as in the Text module, only with a parse function that can consume a lazy Text incrementally." This seems to imply I am supposed to use the lazy version of Text, and not the strict version. – dri Dec 09 '13 at 13:47
  • Yeah, I can understand that attoparsec might now support all features with attoparsec, but I can't understand how importing the lazy text module actaully gives you the non lazy version.... I will file a bug with them later today and put the link here, so we can all follow the discussion with bated breath :) – jamshidh Dec 09 '13 at 16:02
  • Here is the bug report https://github.com/bos/attoparsec/issues/52 – jamshidh Dec 09 '13 at 16:07

0 Answers0