Skip to content

Control Monad instance for linear arrows#493

Merged
aspiwack merged 1 commit intotweag:masterfrom
konn:function-as-a-control
Dec 18, 2025
Merged

Control Monad instance for linear arrows#493
aspiwack merged 1 commit intotweag:masterfrom
konn:function-as-a-control

Conversation

@konn
Copy link
Copy Markdown
Contributor

@konn konn commented Dec 13, 2025

FUN r has only a data Functor instance, but it can be given Control Monad structure provided that r is Dupable. This PR just adds that instance.

@aspiwack
Copy link
Copy Markdown
Member

Indeed. In fact, I believe it's an equivalence: if FUN 'One r is an applicative functor, then r is dupable (i.e. a comonoid). I think this free with the lax-monoidal functor presentation of applicatives (but I didn't work out if the laws actually align, surely they do).

Question: do you need that soon (aka should I cut a release)?

@konn
Copy link
Copy Markdown
Contributor Author

konn commented Dec 15, 2025

Indeed. In fact, I believe it's an equivalence: if FUN 'One r is an applicative functor, then r is dupable (i.e. a comonoid).

Agreed! We can use (,) <$> id <*> id to implement dup.

I think this free with the lax-monoidal functor presentation of applicatives (but I didn't work out if the laws actually align, surely they do).

Sounds interesting, let me know if you make it out!

Question: do you need that soon (aka should I cut a release)?

Well, they are definetely useful (for, e.g., duplicating Linearly tokens until linear constraints land in GHC), but we can do the same thing with Reader monads. So I'm not in a hurry :-)

@aspiwack
Copy link
Copy Markdown
Member

It's likely that I avoided adding a monad for FUN 'One because I don't like the error messages that you get when you forget an argument in a monad. But they aren't really much better without a monad instance, presumably. So let's merge this.

I'll cut a release in January.

@aspiwack aspiwack merged commit b459859 into tweag:master Dec 18, 2025
7 checks passed
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