<div dir="ltr"><div>In Scope.hs there are some functions I feel difficult to understand,</div><div>Why fmap/foldmap/traverse is applied three times?<br></div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">instance</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Functor</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">=></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Functor</span><span style="color:rgb(212,212,212)"> (</span><span style="color:rgb(86,156,214)">Scope</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">b</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)">) </span><span style="color:rgb(86,156,214)">where</span></div><div><span style="color:rgb(212,212,212)">  fmap f (Scope a) </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> Scope (fmap (fmap (fmap f)) a)</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">{-# INLINE fmap #-}</span></div><br><div><span style="color:rgb(96,139,78)">-- | @'toList'@ is provides a list (with duplicates) of the free variables</span></div><div><span style="color:rgb(86,156,214)">instance</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Foldable</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">=></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Foldable</span><span style="color:rgb(212,212,212)"> (</span><span style="color:rgb(86,156,214)">Scope</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">b</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)">) </span><span style="color:rgb(86,156,214)">where</span></div><div><span style="color:rgb(212,212,212)">  foldMap f (Scope a) </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> foldMap (foldMap (foldMap f)) a</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">{-# INLINE foldMap #-}</span></div><br><div><span style="color:rgb(86,156,214)">instance</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Traversable</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">=></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Traversable</span><span style="color:rgb(212,212,212)"> (</span><span style="color:rgb(86,156,214)">Scope</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">b</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">f</span><span style="color:rgb(212,212,212)">) </span><span style="color:rgb(86,156,214)">where</span></div><div><span style="color:rgb(212,212,212)">  traverse f (Scope a) </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> Scope </span><span style="color:rgb(212,212,212)"><$></span><span style="color:rgb(212,212,212)"> traverse (traverse (traverse f)) a</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">{-# INLINE traverse #-}</span></div></div></div></div>