Conversation
* Define `null` and `length`. * Use `liftA2` in case that's better for the underlying `Applicative`.
ec24da5 to
980e381
Compare
konsumlamm
left a comment
There was a problem hiding this comment.
I'm not sure I'm convinced about the need for mapMWithKey. I don't know of any similar function in other related packages. Do you have benchmarks that show a significant speedup?
I can write one. This is a general problem; deferring data structure construction until the very end (building up chains of closures) is awful. |
|
@konsumlamm, here's a test program: {-# language BangPatterns #-}
module Main where
import Data.PQueue.Prio.Min (MinPQueue)
import qualified Data.PQueue.Prio.Min as Q
import Control.Monad.Trans.State.Strict
glump :: MinPQueue Int Int
glump = Q.fromList [(a, a) | a <- [1..2*10^6]]
hoom :: MinPQueue Int Int -> MinPQueue Int Int
hoom = flip evalState 0 . Q.mapMWithKey
(\x y -> do
!old <- get
put (old + 1)
pure (x + y + old))
main = print $ take 3 $ Q.toAscList (hoom glump)On my system, this runs in (give or take) If I use That seems to me like enough to care about. |
980e381 to
9f2613e
Compare
* Add `mapMWithKey`, a version of `traverseWithKey` optimized for strict monads. * Clean out some cruft.
9f2613e to
975e89e
Compare
konsumlamm
left a comment
There was a problem hiding this comment.
Next time, please wait until the PR has been approved/re-reviewed before you merge, to make sure that the comments really have been addressed.
Improve folding and traversing. Add
mapMWithKey(for traversing in strict monads). Clean up cruft.