Proposal: rename Data.Map.fromAscList to Data.Map.unsafeFromAscList

Chris Eidhof chris at
Fri Apr 24 09:21:20 EDT 2009


On 24 apr 2009, at 14:51, Neil Mitchell wrote:

> I totally disagree. unsafe/unchecked means nothing other than "beware
> of the bogey monster", or for most Haskell users, "just another
> function that might launch missiles". fromAscList has the specific
> precondition for this function in the name. Should we call unsafeHead?
> uncheckedHead? mightCrashIfNotConsHead?

No, but the functions you mentioned do fail immediately. If I use a  
head on an empty list I get an error immediately. If I use fromAscList  
incorrectly I get an error only when I try to lookup elements. This  
makes it hard to debug if you didn't make this error before. I don't  
mind a runtime error in this case, but I very much want to know where  
my bug is.


> Thanks
> Neil
> On Fri, Apr 24, 2009 at 1:36 PM, Christian Maeder
> <Christian.Maeder at> wrote:
>> There is an old thread about this, where Daan suggested "unchecked"
>> instead of "unsafe".
>> "unsafe" reminds to "IO" stuff.
>> Didn't you read the comment about fromAscList? Isn't the name long
>> enough to scare you?
>> Would you have not taken "unsafeFromAscList" under the same
>> circumstances you've chosen "fromAscList"?
>> Cheers Christian
>> Chris Eidhof wrote:
>>> Hey all,
>>> I had some code where the function elems said a certain key was  
>>> present,
>>> but looking it up returned a Nothing. After some debugging I found  
>>> out
>>> that it did work if I used Prelude's lookup in combination with  
>>> toList.
>>> After even more debugging it turned out there was a fromAscList
>>> somewhere deep down in my code where it should have been a fromList.
>>> Now, I know that I shouldn't have used fromAscList and that it was
>>> totally my fault. I also realize this is something that can't  
>>> easily be
>>> checked using the type system, so I propose we do the next best  
>>> thing:
>>> prefix the name with 'unsafe'.
>>> -chris
>> _______________________________________________
>> Libraries mailing list
>> Libraries at

More information about the Libraries mailing list