[Haskell-cafe] Re: Debugging partial functions by the rules

S. Alexander Jacobson alex at alexjacobson.com
Fri Nov 17 02:17:37 EST 2006


As long as we are doing this, perhaps we should also discourage the 
use of (head list)?

-Alex-

______________________________________________________________
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com


On Fri, 17 Nov 2006, Donald Bruce Stewart wrote:

> dons:
>> dmhouse:
>>> On 16/11/06, oleg at pobox.com <oleg at pobox.com> wrote:
>>>> And if we are absolutely positive that the value is (Just x),
>>>> we can always write
>>>>        maybe (assert False undefined) id v
>>>
>>> It should be pointed out that Data.Maybe does export a less well-known
>>> function, fromMaybe:
>>>
>>> fromMaybe z = maybe z id
>>>
>>> This can be used to make the 'maybe X id' case a bit tidier (although
>>> technically it's not a save on characters).
>>
>> How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in
>> favour of:
>>
>>     Just _ = x  -- which will give you the precise line number
>>
>>     maybe (assert False)
>>
>>     maybe id
>>
>>     fromMaybe
>>
>> It seems to me this is one cause of mysterious newbie errors we
>> could easily discourage, with little harm.
>
> Btw, I'm not seriously suggesting removing it ;)
> It could be discouraged ever so slightly in the haddocks though.
>
> I'd encourage those worried about fromJust not to use it though, and
> perhaps try:
>
>    import Debug.Trace.Location
>    fromMaybe (failure assert "my just was nothing")
>              (Nothing :: Maybe ())
>
>    $ ./a.out
>    *** Exception: A.hs:5:34-39: my just was nothing
>
> instead of:
>
>    fromJust (Nothing :: Maybe ())
>
>    $ ./a.out
>    *** Exception: Maybe.fromJust: Nothing
>
> While Dana and Neil work on more tools for spotting these for us.
>
> -- Don
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list