
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... Cheers, hvr