Lightning: display the last pack

I ran into a problem using zippers and lens . Consider the following example:

{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeOperators #-} import Control.Lens import Control.Zipper data A = AA { _aa :: A } | AB { _ab :: B } deriving (Show) data B = B deriving (Show) makeLenses ''A makeLenses ''B main :: IO () main = do let a = AA $ AB $ B z :: Top :>> A z = zipper a zAA :: Maybe (Top :>> A :>> A) zAA = z & within aa zAB :: Maybe (Top :>> A :>> B) zAB = z & within (aa . ab) return () 

As you can see, I can navigate from Top :>> A to Top :>> A :>> A and Top :>> A :>> B

Having an ab lens, how can I move from Top :>> A :>> A ( zAA ) to Top :>> A :>> B ( zAB ) without using upward - just matching with the lens on the last pair?

+6
source share
1 answer

Basically, you cannot.

To change the type of current focus, you will need to move up. The type that you will β€œseal” has already been fixed inside the zipper. It contains the second half of the round or lens that have already brought you up to this point. You have already opened the lens or bypass, and the "up" closes the changes, writing them back to the surrounding context.

+2
source

Source: https://habr.com/ru/post/980719/


All Articles