There are two kinds of functions that might be callled unsafe:<br>- non-total functions like head<br>- functions that require some precondition is met like fromAscList<br><br>First kind is too common to be prefixed with &quot;unsafe&quot;. 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.<br>
<br>Best regards<br><br>Christopher SkrzÄ™tnicki<br><br><div class="gmail_quote">On Fri, Apr 24, 2009 at 14:51, Neil Mitchell <span dir="ltr">&lt;<a href="mailto:ndmitchell@gmail.com">ndmitchell@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I totally disagree. unsafe/unchecked means nothing other than &quot;beware<br>
of the bogey monster&quot;, or for most Haskell users, &quot;just another<br>
function that might launch missiles&quot;. fromAscList has the specific<br>
precondition for this function in the name. Should we call unsafeHead?<br>
uncheckedHead? mightCrashIfNotConsHead?<br>
<br>
Adding a check for the precondition would be the ideal thing to do,<br>
but I wouldn&#39;t want to do it if it added an extra comparison or was<br>
any runtime cost at all. Perhaps adding checkedFromAscList might be<br>
acceptable, but I can&#39;t imagine anyone would call it until they&#39;d got<br>
it wrong the first time, at which point the chances of them getting it<br>
wrong again are quite low.<br>
<br>
Thanks<br>
<font color="#888888"><br>
Neil<br>
</font><div><div></div><div class="h5"><br>
On Fri, Apr 24, 2009 at 1:36 PM, Christian Maeder<br>
&lt;<a href="mailto:Christian.Maeder@dfki.de">Christian.Maeder@dfki.de</a>&gt; wrote:<br>
&gt;<br>
&gt; There is an old thread about this, where Daan suggested &quot;unchecked&quot;<br>
&gt; instead of &quot;unsafe&quot;.<br>
&gt; <a href="http://www.haskell.org/pipermail/haskell/2004-March/013787.html" target="_blank">http://www.haskell.org/pipermail/haskell/2004-March/013787.html</a><br>
&gt;<br>
&gt; &quot;unsafe&quot; reminds to &quot;IO&quot; stuff.<br>
&gt;<br>
&gt; Didn&#39;t you read the comment about fromAscList? Isn&#39;t the name long<br>
&gt; enough to scare you?<br>
&gt;<br>
&gt; Would you have not taken &quot;unsafeFromAscList&quot; under the same<br>
&gt; circumstances you&#39;ve chosen &quot;fromAscList&quot;?<br>
&gt;<br>
&gt; Cheers Christian<br>
&gt;<br>
&gt; Chris Eidhof wrote:<br>
&gt;&gt; Hey all,<br>
&gt;&gt;<br>
&gt;&gt; I had some code where the function elems said a certain key was present,<br>
&gt;&gt; but looking it up returned a Nothing. After some debugging I found out<br>
&gt;&gt; that it did work if I used Prelude&#39;s lookup in combination with toList.<br>
&gt;&gt; After even more debugging it turned out there was a fromAscList<br>
&gt;&gt; somewhere deep down in my code where it should have been a fromList.<br>
&gt;&gt;<br>
&gt;&gt; Now, I know that I shouldn&#39;t have used fromAscList and that it was<br>
&gt;&gt; totally my fault. I also realize this is something that can&#39;t easily be<br>
&gt;&gt; checked using the type system, so I propose we do the next best thing:<br>
&gt;&gt; prefix the name with &#39;unsafe&#39;.<br>
&gt;&gt;<br>
&gt;&gt; -chris<br>
&gt; _______________________________________________<br>
&gt; Libraries mailing list<br>
&gt; <a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
&gt;<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</div></div></blockquote></div><br>