Deprecate Foldable for Either

amindfv at gmail.com amindfv at gmail.com
Sun Mar 5 02:16:04 UTC 2017


To Richard's point, though, the ability right now to have e.g. Cofree (Compose [] (Either b)) is in direct conflict with not allowing much simpler terms that no one would ever want to call, e.g.:

sum ([1,2,3], 1) == 1

At the moment, we're picking points on the expressiveness-correctness spectrum.

Would David's proposal of making Foldable a qualified import not allow us to have our cake and eat it too?

Tom


> El 3 mar 2017, a las 23:10, Edward Kmett <ekmett at gmail.com> escribió:
> 
> 100% this. Cofree Maybe is a a nicely general encoding of a non-empty list that shows how closely related it is to a rose tree Cofree []. It'd lose its ability to be folded if Maybe ceased to be Foldable. 
> 
> When I'm showing how the cofree comonad works, I often take time to work up those examples along with Cofree ((->) e) as an (infinite) Moore machine. About 3-4 examples in, it usually clicks.
> 
> instances on Either e, and Maybe, Identity, (,) e, etc. are all building blocks that are commonly used for larger things like this.
> 
> As you enumerate all the simple functors we have lying around in Haskell, looking at what they do when you compute `Cofree f` or `Free f` tends to be quite informative.
> 
> This teaching approach breaks down completely once you start cutting arbitrary holes in instance coverage and making everyone remember where those holes are.
> 
> -Edward
> 
>> On Fri, Mar 3, 2017 at 5:04 PM, David Menendez <dave at zednenem.com> wrote:
>>> On Thu, Mar 2, 2017 at 1:12 PM, Kris Nuttycombe <kris.nuttycombe at gmail.com> wrote:
>> 
>>> As with all of these discussions, the point of having Either be Foldable is not that you're going to call foldMap on an Either value directly. Instead, it is that you be able to pass whatever sort of foldable thing you choose (which Either certainly is) to a function that only requires foldability of its input. By removing or damaging the Foldable instance for Either, you don't simply prevent people from encountering problems that will be resolved the first time they test their software - you make a whole universe of nicely polymorphic functions unavailable for them to use without additional effort.
>> 
>> Not just polymorphic functions. Many higher-order type constructors have Foldable instances based on their parameters. For example,
>> 
>> data Cofree f a = a :< f (Cofree f a)
>> 
>> instance Foldable f => Foldable (Cofree f a) where
>> 	foldMap f (a :< as) = f a <> foldMap (foldMap f) as
>> 
>> Without the instance for Either b, we lose the instances for Cofree (Either b) and Cofree (Compose [] (Either b)), both of which seem reasonable and useful.
>> 
>>> In particular, the idea that one should make all such functions partial by throwing an error is repugnant.
>> 
>> Yes, that seems like the worst possible solution. Better would be some way to give a warning when calling an overloaded function at a particular type.
>> 
>> -- 
>> Dave Menendez <dave at zednenem.com>
>> <http://www.eyrie.org/~zednenem/>
>> 
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20170304/90e13dcd/attachment.html>


More information about the Libraries mailing list