Is there something like a continuation Arrow transformer?
Is there something like a continuation Arrow transformer?
The ContT monad transformer has a interesting property: If there is a * -> * type such as Set, that has well-defined monadic operations, but can't have a Monad instance due to some constraints (here Ord a), it's possible to wrap it in ContT (ContT r Set) to get a monad instance, and defer the constraints outside it, like when we inject Set into ContT r Set. See Constructing efficient monad instances on Set using the continuation monad.
Is there something similar for arrows? An arrow transformer that'd allow to wrap an "almost arrow" into it, getting a valid Arrow instance, and defer problematic constraints to the part where we inject the "almost arrow" into it?
For example, if we had a type AlmostArrow :: * -> * -> * for which we'd have the usual Arrow operations, but with constraints, such as
arr' :: (Ord a, Ord b) => (a -> b) -> AlmostArrow a b
(>>>') :: (Ord a, Ord b, Ord c) => AlmostArrow a b -> AlmostArrow b c -> AlmostArrow a c
As a bonus, if yes, is there some nifty, generic category-theory way how to derive both ContT and such an arrow transformer?
K2-Think
Yes, there is an arrow transformer analogous to ContT called ArrowCont from the arrows package. It serves a similar purpose of deferring constraints by wrapping an arrow with a continuation mechanism, much like how ContT defers monad constraints.
ArrowCont as the Continuation Arrow Transformer
The ArrowCont type (defined in Control.Arrow.Cont) is a transformer that wraps an arrow ...
GPT-5
Yes. The profunctors package gives you exactly the “continuation/CPS for arrows” you’re looking for: the Cayley construction for profunctors.
- Type: newtype Cayley p a b = Cayley (forall r. p b r -> p a r)
- Module: Data.Profunctor.Cayley (in the profunctors package)
Intuition
- Arrows are monoids in the monoidal category of profunctors (Paterson: “Arrows are Monads?” / “Arrows as Monoids”).
- ...
o3
No – at least not in the sense in which the Codensity / ContT trick turns an
“almost‐monad’’ into a genuine Monad.
Why the trick works for monads
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r }
does not use any of the operations of the underlying type constructor m
inside the Monad instance
instance Monad (ContT r m) where
retu...
o3 Pro
Yes – you can do exactly the same trick for arrows.
The easiest way of doing it is to take the free arrow over the
profunctor that you already have. The module
Control.Arrow.Free -- from the package free
contains the required data-type and functions.
- The free arrow transformer -----------------------------...
Claude 3.7 Sonnet
Arrow Continuation Transformer for Deferring Constraints
Yes, there is indeed an arrow transformer analogous to ContT for monads that allows you to defer constraints on "almost arrows". This is the Continuation Arrow Transformer (sometimes called ContArrow or Codensity Arrow).
The Problem
In the case of monads, ContT r Set allows operations on Set to be composed without requi...
Gemini 2.5 Pro
This is a fantastic and insightful question. The analogy between your AlmostArrow problem and the ContT-for-Set trick is spot on. The answer is "yes, there is a direct analogue", but "no, it unfortunately doesn't solve your specific constraint problem". The reason why it fails is very instructive.
Let's break it down.
The Arrow Analogue to the Continuation Monad
The continuation monad...
DeepSeek R1
Recall that in the monad case, ContT is defined as:
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r ...
o4 mini
Yes – nothing magic was hiding in the answer, you just take the same “codensity/continuation” trick you do for monads and apply it to arrows. In fact an Arrow is just a monoid in the promonoidal category of profunctors, and the codensity construction on any monoid in a (pro-)monoidal category gives you exactly the “continuation transformer” for that monoid.
Concretely, suppose you have an “alm...
Claude Opus 4
This is a fascinating question about whether the continuation monad transformer pattern can be lifted to arrows. Let me explore this systematically.
The Short Answer
Yes, there is a continuation arrow transformer! It's called ContA or ContArrow, though it's not as commonly implemented in Haskell libraries as ContT. The construction follows a similar pattern to ContT.
The Construct...
You need to be logged in to submit an answer