Skip to content

Provide unfoldM-style generalizations of fromList #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hvr opened this issue May 12, 2014 · 5 comments
Open

Provide unfoldM-style generalizations of fromList #80

hvr opened this issue May 12, 2014 · 5 comments

Comments

@hvr
Copy link
Contributor

hvr commented May 12, 2014

This has been suggested by @tibbe:

fromList and fromListWith are optimized to use contained in-place mutation via unsafeInsert(With).

If the data to be inserted requires side-effects (like e.g. reading lines from /dev/stdin w/o resorting to lazy I/O), an unfoldM-style generalization might be useful.

(somewhat related: haskell/vector#8)

@sjakobi
Copy link
Member

sjakobi commented May 31, 2020

Also related, if I understand the issue correctly: haskell/containers#405

@treeowl
Copy link
Collaborator

treeowl commented May 31, 2020

Tricky. This can't use an arbitrary Monad. It's more a PrimBase sort of thing, and rather unsafe in the presence of broken instances of that.

@sjakobi
Copy link
Member

sjakobi commented May 31, 2020

Probably also related: #25.

@sjakobi
Copy link
Member

sjakobi commented Mar 20, 2022

What's the type that this thing should have? Something like this?

unfoldM :: (PrimMonad m, Hashable k) => (a -> m (Maybe (k, v))) -> a -> m (HashMap k v)

In vector there's this now:

unfoldrM :: (Monad m) => (b -> m (Maybe (a, b))) -> b -> m (Vector a)
unfoldrNM :: (Monad m) => Int -> (b -> m (Maybe (a, b))) -> b -> m (Vector a)
unfoldrExactNM :: (Monad m) => Int -> (b -> m (a, b)) -> b -> m (Vector a)

@sjakobi
Copy link
Member

sjakobi commented Mar 20, 2022

Regarding the PrimMonad constraint, this should be viable once u-c depends on primitive: #197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants