[Haskell-cafe] Foldable, Traversable and choosing an order
David Feuer
david.feuer at gmail.com
Tue Sep 24 22:09:08 UTC 2019
On Mon, Sep 23, 2019, 3:05 PM Juan Casanova <juan.casanova at ed.ac.uk> wrote:
My types:
>
> data SOTermPF fn p f = ConstF fn | Proj Int | CompF p [f] deriving Eq
newtype SOTermF fn f = SOF (SOTermPF fn f f) deriving Eq
>
Here's a more modular option for the Traversable instance.
import Data.Bitraversable
import Data.Bifoldable
import Control.Applicative
import Data.Traversable
instance Bifoldable (SOTermPF fn) where
bifoldMap = bifoldMapDefault
instance Bitraversable (SOTermPF fn) where
bitraverse _f _g (ConstF fn) = pure (ConstF fn)
bitraverse _f _g (Proj i) = pure (Proj i)
bitraverse f g (CompF p fs) =
liftA2 CompF (f p) (traverse g fs)
instance Foldable (SOTermF fn) where
foldMap = foldMapDefault
instance Traversable (SOTermF fn) where
traverse f (SOF q) = SOF <$> bitraverse f f q
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190924/4ce72b9c/attachment.html>
More information about the Haskell-Cafe
mailing list