Burning bridges

Andreas Abel andreas.abel at ifi.lmu.de
Thu May 23 14:03:16 CEST 2013


On 22.05.2013 18:41, Ben Gamari wrote:
> Ian Lynagh <ian at well-typed.com> writes:
>> The Prelude is a bizarre snapshot of what was common (or perhaps even
>> what existed?) more than a decade ago. For example, it includes 'mapM'
>> and 'sequence', but not 'when'. Here are the usage counts for the ghc
>> package:
>>
>>      mapM        562
>>      mapM_       175
>>      sequence    41
>>      sequence_   8
>>      when        205
>>      unless      84
>>
>> and while this is only one package, I would be surprised if 'sequence'
>> isn't generally less used than 'when'. I would also expect that most
>> mapM users would also use when, so would need to import Control.Monad
>> anyway, at which point there's no point having mapM in Prelude (although
>> that argument is diminished if the generalised mapM is exported
>> instead).
>>
> I agree that the subset of functions exposed by the Prelude is a bit
> strange. Perhaps when should be added; perhaps sequence should be
> dropped. Either way, both of these discussions are I think mostly
> orthogonal to the decision of making what is currently in the Prelude
> polymorphic.
>
>> The Prelude is also bizarre due to being very broad, which also causes
>> headaches with where to put it when splitting base up (the IO functions
>> in particular are problematic).
>>
>>> Given the prominence of Monads in Haskell,
>>> it might be perplexing to find (f)map exported by the Prelude yet not
>>> mapM.
>>
>> Well, why should map be exported by Prelude?
>>
>> If you want to do other things with lists, like 'sort' them, then you
>> need to import Data.List, which makes a lot of sense. But if you want to
>> 'scanl1' a list (when's the last time you did that?), then for
>> historical reasons the function is magically imported through the
>> Prelude.
>>
>> So why shouldn't you need to tell the compiler (i.e. "import Data.List")
>> if you want to do /anything/ with a list, including 'scanl1' or 'map'?
>>
> In the case of these monomorphic functions on lists you may have a
> point. That being said, I believe that fmap has a place in the Prelude
> and my original point holds in this case as well.
>
> I would argue that mapping over functors with pure functions
> and monadic actions are both needed often enough that requiring an
> import for either would be unduly onerous. I would be interested to hear
> if others disagree with this premise.

When I use ghci as a calculator, I need the Prelude, including map.

When I do serious programming, then it is mostly monadic, then I am fine 
with importing stuff.  I do not need mapM in the Prelude.  [But since it 
is there, and used in existing code, it should probably stay (in a 
generalized form).]


-- 
Andreas Abel  <><      Du bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.abel at ifi.lmu.de
http://www2.tcs.ifi.lmu.de/~abel/



More information about the Libraries mailing list