ekmett / profunctors

Haskell 98 Profunctors
http://hackage.haskell.org/package/profunctors
Other
70 stars 43 forks source link

Potential additional superclass of Traversing? #72

Open Zemyla opened 5 years ago

Zemyla commented 5 years ago

Something that's Traversing should perhaps be, in addition to being Strong and Choice, also something that represents being able to go over a fixed number of values. If there were some kind of numbered Vec, I could see it going something like this:

class Profunctor p => TraversingFixed p where
  traverseFixed :: KnownNat n => p a b -> p (Vec n a) (Vec n b)

The other way I could see it happening is by using the fact that a Distributive always has the same number of values in it, because it's isomorphic to x -> a for some x:

class Profunctor p => TraversingFixed p where
  traverseDist :: (Traversable f, Distributive f) => p a b -> p (f a) (f b)

I honestly have no idea how to convert the former to the latter, though, or what to do if the f to be traversed is infinite, because infinite traversals in Haskell can be meaningful. I'm also not entirely sure how a hypothetical wander analogue of traverseFixed would go, since the point of Applicative is that it can combine an arbitrary number of fixed effects.

phadej commented 4 years ago

Distributive is alone is not enough. The r in (->) r ~ f must be ordered. In Vec n case r ~ Fin n, and has Enum, Bounded instances which agree with Traversable (Vec n). But in general, i.e. with just Distributive.

I think you try to generalise binary-product into "finite products". Maybe (Traversable f, Distributive f) is a way to say that, but I'm not sure.