-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
types - recurse over same type? #103
Comments
It's a bit unfortunate that when the types are the same it degenerates
to the identity traversal. I think that if `types` **at least went one
level deep**, then the recursive `transform` would be a one-liner:
```
transform :: (...) => (a -> a) -> (a -> a)
transform f = f . over types f
```
A non-recursive traversal composes better and has nicer properties than
a recursive (SYB-style) one. In particular, the above shows that a
non-recursive traversal can be used to create recursive traversals quite
concisely (and not conversely). In addition, recursive traversals
probably break some traversal laws (`over h f . over h g = over h (f .
g)`), because of the overlapping foci (the usual suspect). For those
reasons they might not seem to be as fundamental as non-recursive
traversals.
|
After further inspection following your tip regarding non-recursive traversals it seems like λ> descendBi f expr
Mul (Sub (Lit 1) (Lit 2)) (Lit 3)
λ> descendBi ((+1) :: Int -> Int) expr
Add (Sub (Lit 2) (Lit 3)) (Lit 4)
λ> U.childrenBi expr :: [Expr]
[Add (Sub (Lit 1) (Lit 2)) (Lit 3)]
λ> U.childrenBi expr :: [Int]
[1,2,3] |
Is there a way to implement this using current |
I might be mistaken, but I don't think you can. |
If this behaviour isn't changing any time soon (from the above discussion, it's not clear to me whether it even can be "fixed"), it would be great to at least have a comment in the documentation. I've just spent a while debugging an issue where I was implicitly expecting |
Hi! First I'd like to thank you for this super cool package!
I was wondering why doesn't
types
recurse deeper when the Traversal focus has the same type as the "big" outer type.Example:
When I run
over types f expr
i get:Mul (Sub (Lit 1) (Lit 2)) (Lit 3)
- meaning only the outer Expr has been transformed (shallow).When I run
over (types @Int) (+1) expr
I get:Add (Sub (Lit 2) (Lit 3)) (Lit 4)
- meaning all of the Ints have been transformed (deep).Coming from uniplate and Control.Lens.Plated I'd expect
over types
to work similarly totransformBi
andtoListOf types
to work likeuniverseBi
, but it only doesn't when the focus type is the same:Any reason for the behaviour differences?
Thanks in advance!
The text was updated successfully, but these errors were encountered: