Closed tvh closed 9 years ago
Looks promising... although one thing I'm not sure I agree with here is the use of the state monad in go
, I think that putting an explicit accumulator on loop
and using forM
instead of forM_
would be clearer and possibly a touch faster.
Also speaking of forM_
, you might be creating a superfluous list there. As in, I'm pretty sure this list is created with older versions of GHC, like 7.6, though this might be fixed in 7.8 or 7.10, whichever implemented the foldl
fusion stuff. This turned foldl
into a good consumer, and might have also made forM_
and forM
good consumers. IIRC, there's a special-cased variant of forM_
for simple numerical ranges in postgresql-simple somewhere, I'm not sure if this function would be applicable here.
Ok, yeah the function I am talking about is forM'
and it's not applicable to this situation. We'll probably need to create a similar function, possibly giving forM'
a better name too.
As far as I know the state monad should not add any overhead on runtime. Not using it may make things more clear though. I adjusted the code to use explicit recursion.
I'll clean this up a little, but it looks good. Thank you!
(Also, I meant foldM
at a couple of spots in my comment above when I said forM
)
This addresses issue 3 of 6457e41491a256ffbbfefd470039e2fd3310a931.
This is not thoroughly tested yet.