Proposal to deprecate and then drop fromJust

Erik de Castro Lopo mle+hs at mega-nerd.com
Tue Feb 24 06:08:32 UTC 2015


Ivan Lazar Miljenovic wrote:

> I've used fromJust in the past when I knew the value would be Just by
> construction.

I have too. And then a less experienced haskell dev saw that usage in code
that I had written and used it elsewhere without the same assurances. I
didn't notice and the Yesod webapp was deployed to production and two
days later we had a report of "Exception: Maybe.fromJust: Nothing" showing
up in web pages. Embarassing to say the least. We removed all usage of
fromJust.

However, if *i* had used fromMaybe to begin with its *highly* likely that
my colleague would have followed my lead and highly likely he would have 
*thought* about the Nothing case.

> 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).

Exactly. This:

   fromMaybe (error "Module.functionName : unexpected Nothing") x

is hugely preferable to fromJust.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the Libraries mailing list