
On 24 February 2015 at 21:06, Oliver Charles
Everyone is talking about wanting a function to do this, but I'd argue an inline case statement is better. Whenever you have
f (fromJust x)
You can write
f (case x of Just x' -> x')
Which is even more fugly if you have more function composition after the usage of fromJust (though I suppose LambdaCase makes it a tad nicer).
Its a little more typing, but the big wins are:
- a warning that you're relying on partiality - a useful error message if your assumption fails, giving you the line number of the pattern match failure.
These are both superior to fromJust, so I can see no reason for it to exist. If its useful in GHCI then add it to your .ghci. If you think everyone should have it by default, then maybe we should have a conversation about a "GHCI prelude".
+1, death to hidden partiality!
ocharles
On 24 Feb 2015 09:36, "Jon Fairbairn"
wrote: Andrew Gibiansky
writes: I am strongly against this, as sometimes you *do* want to use fromJust. For example:
What people want isn’t necessarily good language design.
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.
but you can have your own library that contains “fromMaybe undefined” as well as all the other quick and dirty functions useful for one-off programmes.
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.
Programming languages accrue all sorts of bad practices from that sort of argument. Good Haskell programming involves making the type system move as many errors as possible from run time to compile time.
(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...)
I’m with you on that.
So I’m +1 on the proposal.
-- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com