-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
[original issue 89 by @treeowl]
AccumT is extremely lazy, much like lazy StateT. I suspect that for most purposes, what users actually want is a version that's strict in the accumulator value. That would correspond to instances (at least approximately) like the following:
instance (Monoid w, Functor m, Monad m) => Applicative (AccumT w m) where
pure a = AccumT $ \ !_ -> return (a, mempty)
{-# INLINE pure #-}
mf <*> mv = AccumT $ \ !w -> do
(f, !w') <- runAccumT mf w
(v, !w'') <- runAccumT mv (w `mappend` w')
return (f v, w' `mappend` w'')
{-# INLINE (<*>) #-}
instance (Monoid w, Functor m, Monad m) => Monad (AccumT w m) where
m >>= k = AccumT $ \ !w -> do
(a, !w') <- runAccumT m w
(b, !w'') <- runAccumT (k a) (w `mappend` w')
return (b, w' `mappend` w'')
{-# INLINE (>>=) #-}I think it's also plausible that some users will want a version that's strict in the result pairs, but not in the accumulators. Would you be open to offering the totally strict version, and perhaps the pair-strict version?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels