[Haskell-beginners] Foldable of Foldable

Julian Birch julian.birch at gmail.com
Fri Jan 2 16:28:09 UTC 2015


Thankyou Tony, that works perfectly. I think my biggest problem was that I
didn't even know you could write

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

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 = "

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
```

I'm certainly going to spend some time examining Control.Compose. I think
my Haskell brain bending just went up a level, (sadly, not my actual brain.)

Thanks again,

Julian.

On 2 January 2015 at 15:16, Tony Morris <tonymorris at gmail.com> wrote:

>  A foldable of a foldable is itself foldable. That fact is expressed in
> Control.Compose:
>
>
> https://hackage.haskell.org/package/TypeCompose-0.9.10/docs/Control-Compose.html
>
> instance (Foldable g, Foldable f, Functor g) => Foldable (:. g f)
>
>
> On 03/01/15 01:14, Julian Birch wrote:
>
> Apologies if this isn't clear, I suspect if I understood the terminology
> better I'd already have solved the problem. I've got a foldable of a
> foldable of a.  (Specifically `[Set a]`) and I want to be able to express
> the concept that I can treat `(Foldable f1, Foldable f2) => f1 (f2 a)` as
> `f3 a` i.e. a foldable of a foldable of a can be newtyped to a foldable of
> a.  At least, I think that's right.
>
>  Sadly, my attempts at actually expressing this concept have met with
> incomprehension from GHC, could someone help me out, please?
>
>  Thanks,
>
>  Julian.
>
>
> _______________________________________________
> Beginners mailing listBeginners at haskell.orghttp://www.haskell.org/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150102/a1d17dd7/attachment.html>


More information about the Beginners mailing list