[Haskell-beginners] Foldable of Foldable

Kim-Ee Yeoh ky3 at atamo.com
Fri Jan 2 16:59:22 UTC 2015

On Fri, Jan 2, 2015 at 11:28 PM, Julian Birch <julian.birch at gmail.com>

It's logical, but I couldn't figure it out and none of the web pages I
> could find mentioned it (and the compiler just complains if you try
> "newtype Compose g f a = "

Whatever's on the right of = got eaten by them gremlins, but

newtype (Compose g f) a = O (g (f a))

is equivalent to

newtype Compose g f a = O (g (f a))

Try it. Application is left-associative at the type-level just like

> Also, is the Functor declaration really necessary?  Seems like you can
> write
> ```
> instance (Foldable f1, Foldable f2) => Foldable (Compose f1 f2) where
>   foldr f start (O list) = foldr g start list
>     where g = flip . foldr f

Looks to me the case too.

For the record, here's what's in Conal's TypeCompose 0.9.10:

-- These next two instances are based on suggestions from Creighton
Hogg: instance (Foldable g, Foldable f, Functor g) => Foldable (g :.
f) where  -- foldMap f = fold . fmap (foldMap f) . unO  foldMap f =
foldMap (foldMap f) . unO  -- fold (O gfa) = fold (fold <$> gfa)  --
fold = fold . fmap fold . unO  fold = foldMap fold . unO  -- I could
let fold default

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150102/7be6956d/attachment.html>

More information about the Beginners mailing list