Skip to content

Conversation

@matthewleon
Copy link
Contributor

This is meant as a successor to purescript/purescript-foldable-traversable#70

I believe there should be room in the typeclass hierarchy for efficient, stack-safe traversals within MonadRec. For example, mutable structures like StrMap should benefit from having an efficient fromIterable constructor.

This PR is not meant to replace the proposal for Dissectable. One could use Dissectable to generate a default Iterator for a polynomial type. While doing so would permit iteration in constant stack space, it wouldn't necessarily be efficient; the overhead of Dissectable transformations is considerable. Benchmarks here: https://github.com/matthewleon/purescript-maps/tree/fromDissectable

@paf31
Copy link
Contributor

paf31 commented Jun 13, 2017

Relevant: https://github.com/purescript/purescript-arrays/blob/master/src/Data/Array/ST/Iterator.purs

I'll review in more detail soon, thanks!

@matthewleon
Copy link
Contributor Author

@paf31 sorry for the wasted time, but after a night's reflection, I think we can actually do better than this PR... I don't think the structure of an Iterator should matter to the typeclass. Rather, the important thing is having something like this:

foldRec :: forall t s a b m. Iterable t s => MonadRec m => (a -> b -> m b) -> b -> t a -> m b

I'm going to do some reading, think about this more, and come back to it. But I think I'll start with a separate repo and then see where it fits in the ecosystem. I still think the central idea, to have a typeclass for tail recursive traversals, is a good one.

@matthewleon
Copy link
Contributor Author

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants