Proposal: rename Data.Map.fromAscList to
gtener at gmail.com
Fri Apr 24 09:11:51 EDT 2009
There are two kinds of functions that might be callled unsafe:
- non-total functions like head
- functions that require some precondition is met like fromAscList
First kind is too common to be prefixed with "unsafe". I has also a very
*nice* property: they crash program if they fail. Which is a good thing,
because it makes them always correct. Now, there is a second type. Those
functions may not crash the program, but they could go wrong without notice.
This is a very dangereous situation, since user may run across some strange
results in random places. So we make those functions safe by adding runtime
check. Surely there are times where the user is so much concerned about
performance they might as well choose to omit the check. But IMO Haskell
should be correct in the first place. There is no point in doing wrong
calculcations, even if we do them fast.
On Fri, Apr 24, 2009 at 14:51, Neil Mitchell <ndmitchell at gmail.com> 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?
> Adding a check for the precondition would be the ideal thing to do,
> but I wouldn't want to do it if it added an extra comparison or was
> any runtime cost at all. Perhaps adding checkedFromAscList might be
> acceptable, but I can't imagine anyone would call it until they'd got
> it wrong the first time, at which point the chances of them getting it
> wrong again are quite low.
> On Fri, Apr 24, 2009 at 1:36 PM, Christian Maeder
> <Christian.Maeder at dfki.de> wrote:
> > There is an old thread about this, where Daan suggested "unchecked"
> > instead of "unsafe".
> > http://www.haskell.org/pipermail/haskell/2004-March/013787.html
> > "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 haskell.org
> > http://www.haskell.org/mailman/listinfo/libraries
> Libraries mailing list
> Libraries at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libraries