Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Implement mapM for sequences

Open
#838 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell
Domain
data

Research direction

No file or test path is named. Start by locating the sequence Traversable instance and the Node2 and Deep constructors shown in the issue, then compare their default mapM behavior with the proposed strict construction. Done means an optimized implementation exists for the relevant sequence shapes and its behavior is covered by the project's existing tests.

Written by the indexing model from the issue text.

Description

performance Seq

The Traversable class includes a method

class Traversable t where
  ...
  mapM :: Monad m => (a -> m b) -> t a -> m (t b)

This is normally allowed to take its default definition of mapM = traverse. However, I think it typically makes more sense to use this method as an opportunity to optimize for common, non-Identity, "strict" monads, such as IO and strict StateT. What does this mean in practice? Instead of building up an enormous pile of closures that will eventually be evaluated to produce the result sequence, we can build the result as we go. It could look something like this:

mapM f (Node2 n (Elem a) (Elem b)) = liftA2 (\a' b' -> Node2 n (Elem a') (Elem b')) (f a) (f b)

mapM f (Node2 n (a :: Node _) b) =  do
  !a' <- f a
  !b' <- f b
  pure (Node2 n a' b')

-- Similar for top-level and other Digits

mapM f (Deep n pr m sf) = do
  !pr' <- mapM f pr
  !m' <- mapM (mapM f) m
  !sf' <- mapM f sf
  pure (Deep n pr' m' sf')

The idea is that we build each node as soon as its children are available, rather than risking waiting until all actions are performed to construct anything.

Dominant language
Haskell
Stars
356
Forks
195
Avg merge
2d 17h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/containers

All issues in haskell/containers

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.