[Haskell-cafe] performance question
David Thomas
davidleothomas at gmail.com
Wed Feb 13 18:46:54 CET 2013
The fact that parsec and attoparsec exist and can be pressed into service
with reasonable performance (I think?) on tasks for which regexps are
suitable is probably another big part of the reason no one's done it yet.
I expect much of the plumbing would wind up looking a lot like those,
actually.
On Wed, Feb 13, 2013 at 9:43 AM, David Thomas <davidleothomas at gmail.com>wrote:
> I don't think you can do much about "fails to match the input string" -
> indeed, that's often desired behavior... and "matches the wrong thing" you
> can only catch with testing.
>
> The simplest place template haskell could help with is when the expression
> isn't a valid expression in the first place, and will fail to compile. If
> you're just validating, I don't think you can do better; in order to
> improve your confidence of correctness, your only option is testing against
> a set of positives and negatives.
>
> If you're capturing, you might be able to do a little better, if you are
> able to get some of that info into the types (number of capture groups
> expected, for instance) - then, if your code expects to deal with a
> different number of captured pieces than your pattern represents, it can be
> caught at compile time.
>
> If you're capturing strings that you intend to convert to other types, and
> can decorate regexp components with the type they're going to capture
> (which can then be quickchecked - certainly a pattern should never match
> and then fail to read, &c), and if you are able to propagate this info
> during composition, you might actually be able to catch a good chunk of
> errors.
>
> Note that much of this works quite a bit different than most existing
> regexp library APIs, where you pass a bare string and captures wind up in
> some kind of list, which I expect is much of the reason no one's done it
> yet (so far as I'm aware).
>
>
> On Wed, Feb 13, 2013 at 8:43 AM, Nicolas Trangez <nicolas at incubaid.com>wrote:
>
>> On Wed, 2013-02-13 at 08:39 -0800, David Thomas wrote:
>> > One way in which regexps are "foreign to Haskell-think" is that, if
>> > they
>> > break, they generally break at run-time. This could be ameliorated
>> > with
>> > template haskell
>>
>> Care to elaborate on the "ameliorate using TH" part? I figure regexes
>> would be mostly used to parse some runtime-provided string, so how could
>> compile-TH provide any help?
>>
>> Nicolas
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130213/77af8983/attachment.htm>
More information about the Haskell-Cafe
mailing list