11

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?

Community
  • 1
  • 1
Petr
  • 62,528
  • 13
  • 153
  • 317
  • 1
    A free arrow would surely do the trick. Then you just have to do some junk to make it efficient. – luqui Mar 18 '17 at 20:04

0 Answers0