-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
makeTraverse for non-last type-argument #37
Comments
I'll answer your second question first: in principle, it's not hard to generalize the TH machinery to work on classes of higher arities. In fact, we're already doing so for As for the first question, it may be possible to derive traversals for arbitrary type variables, but it would likely need to work in a rather different way than data T1 a = MkT1 (T2 a)
$(deriveTraversable ''T1) When deriving a instance Traversable T1 where
traverse f (MkT1 x) = MkT1 <$> traverse f x Now let's consider a modified example where we only want to traverse over a single type parameter: data S1 a b = MkS1 (S2 a b)
traverseFirstParamOfS1 :: Applicative f => (a -> f a') -> S1 a b -> f (S1 a' b)
traverseFirstParamOfS1 = $(makeTraverseForFirstParam ...) -- I'm not yet sure what the API would be for this Similarly, we must also "recurse" into
|
One other downside of option (2) that I forgot to mention above is that it assumes you can data V1 f a b c = MkV1 (f a b c) Then you're out of luck, since |
I think it's fine to give up when recursion is needed and there is no class for that kind-pattern. That's what |
OK. What API would you propose for this new functionality? Presumably, all of the existing Also, there's still an annoying hiccup in that |
possible options are from top of my head:
the second would work with data S1 a b = MkS1 (S2 a b) by generating traverseS1a f (MkS1 s2) = MkS2 <$> traverseS2a f s2 where the naming scheme could be provided by a user. This won't work with data V1 f a b c = MkV1 (f a b c) as there we could only generate "full-traversals", i.e. traverseAll
:: Applicative m
=> (forall a1 a2 b1 b2 c1 c2. (a1 -> m a2) -> (b1 -> m b2) -> (c1 -> m c2) -> f a1 b1 c1 -> m (f a2 b2 c2))
-> (a -> m a')
-> (b -> m b')
-> (c -> m c')
-> V1 f a b c
-> m (V1 f a' b' c')
traverseAll f a b c (V1 x) = V1 <$> f a b c x EDIT: thanks for prompt reply. i will try to implement the latter thing. even if it doesn't end up in deriving-compat, i'm curious if it can be made work. |
Take some
data Foo a b c
, and i'd like to derivetraverse
like function for second argument. How hard would it be to parametrisemakeTraverse
to do that, i.e.Even more generally, would be even greater to have unified deriving mechanism for
Bitraversable
and futher kind-variations. (I had uses fortritraverse
), maybe something likeThe text was updated successfully, but these errors were encountered: