-
Notifications
You must be signed in to change notification settings - Fork 56
Iterable typeclass. #70
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
Conversation
Following discussion at purescript-deprecated/purescript-eff#22 (comment)
|
I was originally thinking this could go into |
| -- | be written for the Eff monad. For an example, see `iterableArray`, | ||
| -- | below. | ||
|
|
||
| class Iterable i where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it more, this might not be the best name. Other languages use this name for something more like generators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Foreachable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this approach is still part of the discussion, then I'm thinking something like FoldableE and TraversableE, since really what is being proposed are just optimized versions for Eff of these two classes, and this follows the precedent of foreachE.
Sure. I didn't think too much about where to put it... Was happy to just write some code and get it out there to see if it worked / what people thought. Can we pick one or the other, though? Moving the discussion back to eff would be simple enough, but maybe there are some good reasons to split it off? |
|
The original point of this was to be able to emulate I'd just like to point out that there is an unsafe option too. However, while |
|
Actually, this does give a way to build a safe traverse_ f fb = unsafeFoldM (\_ a -> void (f a)) unit fb |
|
Ignore me actually, |
This might actually just do the trick in terms of what I'm looking for. It actually looks roughly equivalent to what I was trying to write before, with the additional use of |
Well, from an arbitrary I can see how this really makes the API less ergonomic, though. But then, writing code like In any case, I think your Edit: Oops! Ignore the above sentence... Elaboration below. |
Upon rereading your comments, I came to a better understanding of what this implies. Does this not, in turn, imply that It seems to me that this implies that we should indeed build an |
|
I don't think we need to worry about that instance, because it looks like it is constructing a linked list anyway, so evaluation order should not matter.
Having thought about it some more, I think we should consider a subclass of Foldable and Traversable for Dissectable functors, in the sense of the clowns and jokers paper. This would let us express many folds and traversals using an intermediate zipper structure and a constant amount of stack.
…Sent from my iPhone
On Jun 10, 2017, at 2:13 AM, Matthew Leon ***@***.***> wrote:
Ignore me actually, unsafeFoldM isn't safe after all, because it relies on the values in the Foldable structure being evaluated in the same order they would be mappended together, which is not required by Foldable.
Upon rereading your comments, I came to a better understanding of what this implies. Does this not, in turn, imply that fromFoldable in purescript-arrays needs to be changed? https://github.com/purescript/purescript-arrays/blob/v4.0.1/src/Data/Array.js#L47
It seems to me that this implies that we should indeed build an Iterable-style typeclass, and that Array and StrMap should have fromIterable.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
@matthewleon I reread the paper and started porting it to PureScript. I think it can be very helpful here: http://try.purescript.org/?gist=e0b868cfceff385409c1a1a4b2917e91&backend=core Unfortunately, we can't implement |
This is really fascinating, and I'm eager to read the paper and work on this. |
|
Looking at this code, though, it seems to me that an |
|
...Though perhaps what one does for something like Some unfortunate design choices, it seems. |
Just a note that McBride calls this |
Based on Phil Freeman's code from this conversation purescript#70 (comment) In turn based on McBride, 2007. Clowns to the Left of me, Jokers to the Right: Dissecting Data Structures. http://strictlypositive.org/CJ.pdf
|
I'd be fine with I agree |
|
Where does the |
|
It's from the paper, although while every polynomial function is dissectible, it's not clear that every dissectible functor is polynomial. So perhaps |
|
Ohh I see now yeah, polynomial functors. I don't really know what that means still, but will re-read the paper, it's been a while :) |
Following discussion at purescript-deprecated/purescript-eff#22 (comment)
The
purescript-unsafe-coercedep can be removed if purescript-deprecated/purescript-eff#23 is accepted.Would particularly like input on the documentation.
Also, I have not made
Functora superclass. I'm happy to change that, but so far I haven't seen anything that makes it a requirement, or beneficial.