Skip to content
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

Add instances for Profunctor and Traversing. #247

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

freckletonj
Copy link

@freckletonj freckletonj commented Aug 21, 2021

This is my first pass at adding Profunctor and Traversing instances.

I'm not 100% positive they're correct, though, some hand-rolled experiments seem to match my intuitions so far.

My interest in these instances stems from https://elvishjerricco.github.io/2017/03/10/profunctors-arrows-and-static-analysis.html. In it he builds a tree from FreeTraversing and in breaking it back down is able to build batched effects from singular effects. I'm hoping these instances will help me explore that possibility, we'll see!

Related: #224

@freckletonj
Copy link
Author

updated!

So I'm not sure I understand the tradeoff between strict and lazy state. I would guess that laziness might be necessary for ArrowLoop or MonadFix to work properly... But I'm not sure.

@turion
Copy link
Contributor

turion commented Sep 3, 2021

The difference is whether in a state transition the internal state (i.e. the current MSF continuation) is evaluated to WHNF. In most cases this is done automatically on the next tick because it is needed then.

@freckletonj
Copy link
Author

@turion It's a humble PR, but it should be g2g now!
Thanks for your help writing it (the StateT thing was brilliant), and I'm happy to accept further advice.

Copy link
Contributor

@turion turion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments

@turion
Copy link
Contributor

turion commented Sep 5, 2021

You should definitely squash the commits ;)

add StateT to get types working (needs to be removed)

ah, we can't get rid of the newtype StateT

cleanup

use transformers StateT

use strict StateT

add backwards compatibility

backwards compatibility: Control.Applicative.pure

appease our forefathers

be satisfied!

light refactor
@freckletonj
Copy link
Author

Good recommendations. And I squashed the commits, but if you haven't seen it yet, I tend to use github's Merge Squash feature that does that automatically once right at the end when you merge, it's kinda nice too.

Any other issues you'd like a hand with?

@turion
Copy link
Contributor

turion commented Sep 6, 2021

Looking great! @ivanperez-keera Is this fine to merge for you? I'm only asking since this introduces one dependency (profunctors).

Good recommendations. And I squashed the commits, but if you haven't seen it yet, I tend to use github's Merge Squash feature that does that automatically once right at the end when you merge, it's kinda nice too.

Right, I've just never used it. And I don't know what the commit message will be in that case.

Any other issues you'd like a hand with?

Any that are open, really :)

@freckletonj
Copy link
Author

It actually gives you a prompt to write a commit message.

Cool I'll take a look at open issues :)

@ivanperez-keera
Copy link
Owner

I'll take a look and get back to you.

@miguel-negrao
Copy link
Contributor

miguel-negrao commented Feb 18, 2022

I believe this would make mapMaybeS and mapMSF special cases of traverse'. Should also work for Vector, Seq, vector-sized's Vector, etc. I find it quite useful.

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.

None yet

4 participants