regex-applicative
regex-applicative copied to clipboard
Mysterious run time difference between two different expressions for the same function
I have the contents of a file and wish to apply one regex to the first line and another regex to each of the other lines. This runs fast:
case lines contents of
[] -> []
h:b -> (:) <$> match hregex h <*> traverse (match bregex) b
This runs slow:
zipWithM match (hregex : repeat bregex) $ lines contents
That's sort of a shame. Just as I'm writing this, I'm realising that the first is probably faster because reductions can be applied to match bregex
just once. Still, I'd be interested to hear your thoughts.