Proposal to deprecate and then drop fromJust

Andrew Gibiansky andrew.gibiansky at gmail.com
Tue Feb 24 06:12:05 UTC 2015


I am strongly against this, as sometimes you *do* want to use fromJust. For
example:

1. Quick and dirty scripting/examples where you don't care about
error-proofing your work and just want it to be done quickly. In that
context, fromJust is a good function.
2. You know by construction that it is a Just constructor. This is usually
not a good design, but sometimes it's useful. Writing an (error "fromJust")
is possible, but annoying.

IMHO removing fromJust would be a bad idea; although it may be overused
there are certainly times and places where it is useful. In addition, it
seems like the *real* issue is that "error" needs to give better stack
traces, so that you do not need to do as Erik suggests and write "
 fromMaybe (error "Module.functionName : unexpected Nothing") x". But I
think that by 7.12 or 7.14 this will happen, as there is work being done in
this direction. It may be a good idea to change the documentation of
`fromJust` to say something like "please never use this unless you really
know you want to".

(That said, I do wish that `head` and `tail` were replaced by `headMay` and
`tailMay`, which you could then use with `fromJust` if you wanted to. But
that's another discussion for adding things from `safe` to `base`,
unrelated...)

Strong -1.



On Mon, Feb 23, 2015 at 9:51 PM, Chris Allen <cma at bitemyapp.com> wrote:

> I'm strongly in favor of removing this so as not to confuse new people
> with partial functions that have impossible type signatures.
>
> +1
>
>
> On 02/23/2015 11:49 PM, Ivan Lazar Miljenovic wrote:
>
>> On 24 February 2015 at 16:42, Erik de Castro Lopo <mle+hs at mega-nerd.com>
>> wrote:
>>
>>> Hi all,
>>>
>>> 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.
>>>
>>> Comments?
>>>
>> I've used fromJust in the past when I knew the value would be Just by
>> construction.
>>
>> That said, I could always have written my own fromJust function with a
>> custom error message, and did switch some of them to direct pattern
>> matches (so that at least the error message said *where* the error
>> occurred).
>>
>> So I'm undecided; maybe (no pun intended!) -0.1.
>>
>>  Erik
>>> --
>>> ----------------------------------------------------------------------
>>> Erik de Castro Lopo
>>> http://www.mega-nerd.com/
>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>
>>
>>
>>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150223/bae799fc/attachment.html>


More information about the Libraries mailing list