I am reading the Zipper article in Haskell Wiki
and I can't understand the up
method defined as:
data Tree a = Fork (Tree a) (Tree a) | Leaf a
data Cxt a = Top | L (Cxt a) (Tree a) | R (Tree a) (Cxt a)
type Loc a = (Tree a, Cxt a)
up :: Loc a -> Loc a
up (t, L c r) = (Fork t r, c)
up (t, R l c) = (Fork l t, c)
In the pattern up (t, L c r)
, t
is the subtree with focus, c
is the context with a hole at current focus, when moving up, why c
doesn't move up but still referenced to the old context? Shouldn't the focus also go up?