5

I've been thinking about whether there's some method that could be added to Traversable to make it compose more cheaply in the presence of expensive functors. The inspiration was Control.Lens.Traversal.confusing, which uses a special Applicative to do something similar.

confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b

Unfortunately, confusing really lives up to its name—I don't understand what it's actually doing. In particular, I have no intuition about Curried.

Furthermore, confusing has a CPS flavor to it, which suggests it's probably too strict for my purpose. Yoneda can be swapped out for Coyoneda to enhance laziness, but I have no idea what to do about the Curried.

dfeuer
  • 48,079
  • 5
  • 63
  • 167
  • 1
    Not really a full answer, but some little bits of intuition I've skimmed from the docs: given `fx :: f a` then `(<*> fx) :: forall r. f (a -> r) -> f r`, ripe to be passed to `Curried`. So it's a bit like a higher-order encoding of the application operator. Furthermore, looking at [its Applicative instance](https://hackage.haskell.org/package/kan-extensions-5.0.1/docs/src/Data-Functor-Day-Curried.html#line-48) you can see that `<*>` is implemented using `.`, like difference lists' `mappend`, which I guess is what the docs mean when they talk about reassociating `<*>` calls. – Benjamin Hodgson Jan 02 '17 at 18:05
  • @BenjaminHodgson, I'm not really after reassociating the `<*>` calls, per se, so maybe `confusing` isn't the right model. What I really want, I think, is to replace `f <$> m <*> (g <$> n)` with `(\mr nr -> f mr (g nr)) <$> m <*> n`, and to do that recursively. I wonder if I need to look less at `Traversable` and more at `Applicative` itself. – dfeuer Jan 02 '17 at 19:19
  • 1
    It's discussed in subsection _8.4.2_ of [_Generic Deriving of Generic Traversals_](https://arxiv.org/abs/1805.06798) – Iceland_jack Aug 05 '18 at 17:11
  • 1
    I also want to point out, that `Yoneda` has the type of `flip fmap` applied to a single argument. `Curried` has the type of `flip (<*>)` applied to a single argument. `(<$> ..) :: forall x. (A -> x) -> F x` and `(<*> ..) :: forall x. F (A -> x) -> F x`. – Iceland_jack Aug 05 '18 at 18:27

0 Answers0