Haskell Foldable Wats (Was: Add conspicuously missing Functor instances for tuples)

David Feuer david.feuer at gmail.com
Wed Feb 17 20:05:25 UTC 2016


The big problem was the goal of allowing Data.Foldable and Data.Traversable
to be imported unqualified. This was fine for Data.Traversable, but not for
Data.Foldable. There are relatively few cases where the Traversable
generalization is confusing or otherwise problematic, but Foldable is just
too "wild".

Once that dubious goal was set, consistency and efficiency demanded some of
the other changes.
On Feb 17, 2016 6:02 AM, "Henning Thielemann" <lemming at henning-thielemann.de>
wrote:

>
> On Mon, 18 Jan 2016, Ryan Scott wrote:
>
> * The Not-A-Wat in Haskell:
>> https://www.youtube.com/watch?v=87re_yIQMDw
>>
>
> I see his examples and draw the opposite conclusions. What he presents are
> perfect Wats and they have eventually moved Haskell to the MatLab league
> where everything is allowed and the programming system accepts almost
> everything the programmer enters.
>
> Sure,
>
> length (2,3) = 1
>> product (2,3) = 3
>> sum (2,3) = 3
>> or (True,False) = False
>>
>
> are all consistent but consistently useless, unintuitive (not only to
> novices) and dangerous. There are alternatives: There was no need to
> generalize 'Prelude.length' using Foldable. I always opposed to the
> argument "put the most general variant to Prelude", because there is no
> clear most general variant or there is one like "length :: Length f => f"
> and you won't like it.
>
> We could reasonably have the Haskell 98 class
>
>   class Length a where
>      length :: a -> Int
>
>   instance Length [a] where
>      length = List.length
>
>   instance Length (a,b) where
>      length _ = 2
>
> This would yield the intuitive
>   length (2,3) = 2
>
> I do not propose to implement this class, because I never encountered a
> situation where I could equally choose between lists and pairs. If at all,
> I can see value in a special TupleSize class. However, the Length class
> proves that the suggestion that the only reasonable result of 'length
> (2,3)' is 1, is plain wrong.
>
> How did we get there? There were three steps that made this Wat possible:
>   1. Foldable.length added
>   2. instance Foldable ((,) a)
>   3. export Foldable.length from Prelude.
>
> For me
>   1. was correct
>   2. was wrong because a programmer should better define a custom type
>      like "data AdornedSingleton a b = AS a b"
>   3. Was wrong because there are multiple ways to generalize 'length'.
>      Without 3. you would have to use explicitly 'length' from Foldable
>      and this way you would have been warned, that strange things may
> happen.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160217/d577e700/attachment.html>


More information about the Libraries mailing list