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

wren ng thornton wren at community.haskell.org
Fri Apr 24 19:30:05 EDT 2009


Chris Eidhof wrote:
> I really like that, Krzysztof. That way there's still the power to do it 
> efficiently but at least you know when you're doing things in an 
> erroneous way. My problem with the current way of doing this is that you 
> get errors in a place where you didn't expect them.
> 
> -chris
> 
> On 24 apr 2009, at 14:14, Krzysztof Skrzętnicki wrote:
> 
>> On the second thought, another thing can be made. Since we know that 
>> fromAscList should take a list of ascending items, we can check 
>> whether it is sorted. If this precondition is not met, we simply call 
>> error. We also rename current fromAscList to unsafeFromAscList. This 
>> is similar to index and unsafeIndex from arrays code.
>>
>> What do you think about this solution?

+1

Depending on the strictness qualities of (un-)safeFromAscList[1], the 
safeFromAscList version could do this check "online" rather than 
scanning the list to verify and then calling unsafeFromAscList[2], which 
would be helpful for list fusion (assuming foldr is used).



[1] Which I think are already strict enough to give the behavior we want.

[2] Impl: just keep a copy of the previous key, if the next key isn't 
monotone then error.

-- 
Live well,
~wren


More information about the Libraries mailing list