Proposal: Foldable typeclass: make foldl' and foldr' class methods

wren ng thornton wren at freegeek.org
Mon Jun 20 20:36:35 CEST 2011


On 6/20/11 2:21 PM, Antoine Latter wrote:
> On Mon, Jun 20, 2011 at 12:02 PM, Duncan Coutts wrote:
>>
>> This should not break much code. In particular it should not break
>> existing type class instance declarations since there is a default
>> definition for instances that don't defined the new methods.
>>
>> The only potential breakage is that foldl' and foldr' are exported via
>> Foldable(..) rather than directly. This could affect modules that use
>> explicit imports.  (I consider this fact to be a slightly unfortunate
>> quirk of the Haskell module system).
>
> What would the broken code look like?


Broken code would look like GHC complaining that uses of foldl' (or
foldr') are ambiguous between the Prelude and Data.Foldable. The ambiguity
is introduced by

    import Data.Foldable (Foldable(..), {-...-})

where the ... does not include foldl' or foldr' and we did not explicitly:

    import Prelude hiding (foldl', foldr', {-...-})

or use -XNoImplicitPrelude, or import Prelude qualified, or... ... ...

Honestly, it's a really bizarre corner case that this would even happen
since often folks will be importing Data.Foldable qualified or will be
importing everything it offers and hiding it from Prelude. In the event
breakage occurs, it's obvious what went wrong and how to fix it. Backwards
compatibility shouldn't even be much of an issue since you can just add
the imports outside of the (..). The only backwards compatibility issue is
folks wanting to give definitions to these new methods, but the standard
CPP hackery can be used to work around that.

-- 
Live well,
~wren




More information about the Libraries mailing list