Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Foldable of Foldable (Tony Morris)
   2. Re:  Foldable of Foldable (Julian Birch)
   3. Re:  Foldable of Foldable (Kim-Ee Yeoh)
   4. Re:  Foldable of Foldable (Julian Birch)


----------------------------------------------------------------------

Message: 1
Date: Sat, 03 Jan 2015 01:16:35 +1000
From: Tony Morris <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Foldable of Foldable
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"

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 list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150103/14ad04e3/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 2 Jan 2015 16:28:09 +0000
From: Julian Birch <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Foldable of Foldable
Message-ID:
        <CAB0TuzC+9MR2G=Egz0zoUJ2pyPqH3Bizo4mXMqM=fbay_hu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <[email protected]> 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 
> [email protected]http://www.haskell.org/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> 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-0001.html>

------------------------------

Message: 3
Date: Fri, 2 Jan 2015 23:59:22 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Foldable of Foldable
Message-ID:
        <capy+zds9a0vlqafgc0rq5oosgh5x03necviyh6sssw02sse...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Fri, Jan 2, 2015 at 11:28 PM, Julian Birch <[email protected]>
wrote:

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
value-level.




> 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-0001.html>

------------------------------

Message: 4
Date: Fri, 2 Jan 2015 17:32:31 +0000
From: Julian Birch <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Foldable of Foldable
Message-ID:
        <cab0tuzcckyy_khpnueyxvuyehso6k32pr+3cunufvgekomy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Ah! That also works. I think I was a bit confused originally, not putting
enough parameter on the left and not enough parens on the right. Being able
to read Conal's code made all the difference.  (Oh, and it should have been
"flip $ foldr f".)

J

On 2 January 2015 at 16:59, Kim-Ee Yeoh <[email protected]> wrote:

> On Fri, Jan 2, 2015 at 11:28 PM, Julian Birch <[email protected]>
> wrote:
>
> 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
> value-level.
>
>
>
>
>> 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
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150102/0bc749a5/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 79, Issue 3
****************************************

Reply via email to