Proposal: rename Data.Map.fromAscList
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.
> 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?
Depending on the strictness qualities of (un-)safeFromAscList, the
safeFromAscList version could do this check "online" rather than
scanning the list to verify and then calling unsafeFromAscList, which
would be helpful for list fusion (assuming foldr is used).
 Which I think are already strict enough to give the behavior we want.
 Impl: just keep a copy of the previous key, if the next key isn't
monotone then error.
More information about the Libraries