Proposal to deprecate and then drop fromJust

Michael Snoyman michael at snoyman.com
Tue Feb 24 10:54:32 UTC 2015


On Tue Feb 24 2015 at 12:47:07 PM Herbert Valerio Riedel <hvr at gnu.org>
wrote:

> On 2015-02-24 at 06:42:22 +0100, Erik de Castro Lopo wrote:
> > We currently have in the Data.Maybe module from base:
> >
> >      fromJust :: Maybe a -> a
> >
> > which newbies often find using hoogle or other search tools and is
> > a huge trap. *Every* usage of the above can be replaced by using
> >
> >       fromMaybe :: a -> Maybe a -> a
> >
> > which forces the user to provide a default value for the case where
> > the Maybe a is a Nothing.
> >
> > The idea would be to deprecate fromMaybe for 7.12 and remove it
> > completely later.
>
> I'm +1 for deprecating (or attach a warning pragma to) 'fromJust' as
> I've been bit by 'fromJust' myself in the past, when I was still mixing
> up 'fromMaybe' and 'fromJust'. Nowadays I don't reach out for 'fromJust'
> anymore at all.
>
> However, I think it'll require a very long deprecation cycle before
> actually removing it from base, as 'fromJust' is officially part of
> Haskell 2010, and there's probably a lot of code out there using
> 'fromJust'...
>
> Relatedly, I was thinking of a separate 'partial-functions' warning
> class, so we could annotate partial functions (head/last/...) in base,
> and have the associated warnings be tunable via a separate GHC -fwarn*
> flag. This could even be generalised to arbitrary warning-classes:
>
>  {-# WARNING[partial] fromJust "Use 'fromMaybe' instead" #-}
>
> I'm sure we would come up with other useful warning-classes...
>
>
>
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.

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.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150224/c0ee78d5/attachment.html>


More information about the Libraries mailing list