Suppose I have a simple GADT.
data Expr a where
Int' :: Integer -> Expr Int
Fun :: Text -> Expr a
(:*) :: Expr (a -> b) -> Expr a -> Expr b
Now, I can define the following traversal over it:
transform :: Applicative f => (forall b. Expr b -> f (Expr b)) -> Expr a -> f (Expr a)
transform f (a :* b) = (:*) <$> transform f a <*> transform f b
transform f v = f v
The type looks curiously a lot like Traversal
from lens. However, not exactly, it's higher ranked.
I can still define «conventional» set
and over
though. view
is more complex, there are some obstacles to avoid (impredicative types), but doable.
Does this construction have a name? Is it supported in any way by the existing lens libraries or researched?