title: What are the differences between lenses and zippers?
body: <p>This is an example of using a zipper in Haskell:</p>
  
  <pre><code>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)
  
  left :: Loc a -&gt; Loc a
  left (Fork l r, c) = (l, L c r)
  
  right :: Loc a -&gt; Loc a
  right (Fork l r, c) = (r, R l c)
  
  top :: Tree a -&gt; Loc a 
  top t = (t, Top)
  
  up :: Loc a -&gt; Loc a
  up (t, L c r) = (Fork t r, c)
  up (t, R l c) = (Fork l t, c)
  
  upmost :: Loc a -&gt; Loc a
  upmost l@(t, Top) = l
  upmost l = upmost (up l)
  
  modify :: Loc a -&gt; (Tree a -&gt; Tree a) -&gt; Loc a
  modify (t, c) f = (f t, c)
  </code></pre>
  
  <p>This is an example of using a zipper in Clojure:</p>
  
  <pre><code>(use 'clojure.zip)
  (require '[clojure.zip :as z])
  
  user&gt; (def z [[1 2 3] [4 [5 6] 7] [8 9]])
  #'user/z
  
  user&gt; (def zp (zipper vector? seq (fn [_ c] c) z))
  #'user/zp
  
  user&gt; zp
  [[[1 2 3] [4 [5 6] 7] [8 9]] nil]
  
  user&gt; (-&gt; zp down)
  [[1 2 3] {:l [], :pnodes [[[1 2 3] [4 [5 6] 7] [8 9]]], :ppath nil, :r ([4 [5 6] 7] [8 9])}]
  
  user&gt; (first (-&gt; zp down))
  [1 2 3]
  </code></pre>
  
  <p>This is an example of using a Lens in Haskell:</p>
  
  <pre><code>data Person = P { name :: String 
                  , addr :: Address 
                  }
  data Address = A { street :: String
                   , city :: String
                   , postcode :: String 
                   }
  
  setPostcode :: String -&gt; Person -&gt; Person
  setPostcode pc p = p { addr = addr p { postcode = pc }}
  </code></pre>
  
  <p>This is an example of using a Lens in Clojure. </p>
  
  <pre><code>(use 'lens)
  
  (defrecord Address [street city postcode])
  (defrecord Person [name age address])
  (defrecord User [uid username identity password])
  
  (def -postcode (mklens :postcode))
  (def -city (mklens :city))
  (def -street (mklens :street))
  (def -address (mklens :address))
  (def -age (mklens :age))
  (def -name (mklens :name))
  (def -uid (mklens :uid))
  (def -username (mklens :username))
  (def -identity (mklens :identity))
  (def -password (mklens :password))
  
  (-get -postcode home)
  
  (-set -postcode home 500)
  </code></pre>
  
  <p>Now it seems both lenses and zippers are functional ways of traversing nested data structures. </p>
  
  <p>My question is: <strong>What are the differences between lenses and zippers?</strong> Is one suited to a particular use case?</p>