<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019, 3:05 PM Juan Casanova <<a href="mailto:juan.casanova@ed.ac.uk">juan.casanova@ed.ac.uk</a>> wrote:</div><div dir="ltr" class="gmail_attr"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My types:<br>
<br>
data SOTermPF fn p f = ConstF fn | Proj Int | CompF p [f] deriving Eq</blockquote></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
newtype SOTermF fn f = SOF (SOTermPF fn f f) deriving Eq<br></blockquote></div><div dir="auto"><br></div><div dir="auto">Here's a more modular option for the Traversable instance.</div><div dir="auto"><br></div><div dir="auto">import Data.Bitraversable</div><div dir="auto">import Data.Bifoldable</div><div dir="auto">import Control.Applicative</div><div dir="auto"><span style="font-family:sans-serif">import Data.Traversable</span><br></div><div dir="auto"><br></div><div dir="auto">instance Bifoldable (SOTermPF fn) where</div><div dir="auto"> bifoldMap = bifoldMapDefault</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">instance Bitraversable (SOTermPF fn) where</span><br></div><div dir="auto"><span style="font-family:sans-serif"> bitraverse _f _g (ConstF fn) = pure (ConstF fn)</span></div><div dir="auto"><span style="font-family:sans-serif"> bitraverse _f _g (Proj i) = pure (Proj i)</span><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif"> bitraverse f g (CompF p fs) =</span></div><div dir="auto"><span style="font-family:sans-serif"> liftA2 CompF (f p) (traverse g fs)</span></div><div dir="auto"><br></div><div dir="auto">instance Foldable (SOTermF fn) where</div><div dir="auto"> foldMap = foldMapDefault</div><div dir="auto"><br></div><div dir="auto">instance Traversable (SOTermF fn) where</div><div dir="auto"> traverse f (SOF q) = SOF <$> bitraverse f f q</div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>