<div dir="ltr"><br><br><div class="gmail_quote">On Tue Feb 24 2015 at 12:47:07 PM Herbert Valerio Riedel <<a href="mailto:hvr@gnu.org">hvr@gnu.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2015-02-24 at 06:42:22 +0100, Erik de Castro Lopo wrote:<br>
> We currently have in the Data.Maybe module from base:<br>
><br>
>      fromJust :: Maybe a -> a<br>
><br>
> which newbies often find using hoogle or other search tools and is<br>
> a huge trap. *Every* usage of the above can be replaced by using<br>
><br>
>       fromMaybe :: a -> Maybe a -> a<br>
><br>
> which forces the user to provide a default value for the case where<br>
> the Maybe a is a Nothing.<br>
><br>
> The idea would be to deprecate fromMaybe for 7.12 and remove it<br>
> completely later.<br>
<br>
I'm +1 for deprecating (or attach a warning pragma to) 'fromJust' as<br>
I've been bit by 'fromJust' myself in the past, when I was still mixing<br>
up 'fromMaybe' and 'fromJust'. Nowadays I don't reach out for 'fromJust'<br>
anymore at all.<br>
<br>
However, I think it'll require a very long deprecation cycle before<br>
actually removing it from base, as 'fromJust' is officially part of<br>
Haskell 2010, and there's probably a lot of code out there using<br>
'fromJust'...<br>
<br>
Relatedly, I was thinking of a separate 'partial-functions' warning<br>
class, so we could annotate partial functions (head/last/...) in base,<br>
and have the associated warnings be tunable via a separate GHC -fwarn*<br>
flag. This could even be generalised to arbitrary warning-classes:<br>
<br>
 {-# WARNING[partial] fromJust "Use 'fromMaybe' instead" #-}<br>
<br>
I'm sure we would come up with other useful warning-classes...<br>
<br><br></blockquote><div><br></div><div>This sounds like a great idea, which I'd support fully. The idea of letting people opt-out of partiality warnings somehow would IMO address the concerns here perfectly.</div><div><br></div><div>Even though I'm strongly opposed to fromJust, I'm -1 on removing it any time soon due to ensuing breakage. I'm on the fence with a standard deprecation warning (since by what I just said we really *aren't* deprecating it), but a WARNING would be great.</div><div><br></div><div>Michael </div></div></div>