Re: like "deriving Read" but faster?
Tikhon Jelvis <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.cafe |
|---|---|
| Message-ID | <CAJN5CV+4xaEHrUvBUvC4d_ffravxR4C6iT392Cnj8D4OXKB0Pw@mail.gmail.com> |
Just Foo { foo = 42 } is valid Haskell syntax. I actually take advantage of
this in patterns sometimes, although it can definitely be a bit confusing.
(And in expressions, I 100% would have extra parentheses, otherwise it's
too visually confusing.)
On Tue, Aug 18, 2026 at 7:45 AM Johannes Waldmann via Haskell-Cafe <
[email protected]> wrote:
> Dear Cafe,
>
> I could use a parser that is equivalent
> to the one produced by "deriving Read" but ...
>
> A) faster, and using less space (Data.Text(.Lazy) instead of String)
> B) streaming (parse a long list literal "[0,1,2, ... ]" in constant space,
> produce the first cons of the result right after reading "[0")
> C) with some minimal error reporting (e.g., some prefix of not-consumed
> input)
>
> perhaps attoparsec with some form of early-commited choice?
>
> I do have something (only for A) at
> https://codeberg.org/jwaldmann/text-read (attoparsec on lazy text)
> and it seems twice as fast as "deriving Read" in my tests.
>
>
> NB: I was quite shocked to see that "deriving Read" accepts
> "Just Foo { foo = 42 }" (no parentheses around the record literal)
> (while "deriving Show" produces them).
>
> - J.W.
>
> _______________________________________________
> Haskell-Cafe mailing list -- [email protected]
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
>
_______________________________________________
Haskell-Cafe mailing list -- [email protected]
To (un)subscribe, modify options or view archives go to:
Only members subscribed via the mailman list are allowed to post.