3 ms·
> You seem to believe Either/Maybe are new ideas. They are not. It's an old pattern which has been used plenty and we have a pretty good idea of how they work.
by pron 11y ago
> You seem to believe Either/Maybe are new ideas. They are not. It's an old pattern which has been used plenty and we have a pretty good idea of how they work.
I don't. I used them first over 15 years ago when Haskell was "the next big thing" and I learned it at university. Fact of the matter is that not enough code has been written with them to say that we know how effective they are.
> If what you said was true, it wouldn't make sense for a hybrid language like Scala to have both. Obviously Scala's designers don't consider exceptions and Either/Maybe "identical", do they?
I wouldn't take lessons from Scala. Scala has inheritance types, sum types, structural types and dynamic types, each can be (and is) used in isolation to solve almost all problems. If there's any language with lots of overlapping features, that would be Scala. After all, it's a language designed to study various approaches, not to recommend the "best" ones.
> You can silence checked exceptions with reckless abandon, but you cannot silence a Maybe just as easily, without resorting to obviously frowned-upon practices
You can silence checked exceptions by doing exactly what you'd be doing to handle Maybe: You need to explicitly handle it. The difference is that you can catch multiple exception types in one block.
> For example, checked exceptions are terrible for generic code, composable code.
They're not. They just don't work too well with Java's limited effect system of checked exceptions. As a matter of fact, "checked exceptions" are the basis for effect systems in languages like Koka, and are also the basis of transformations of Haskell-ish monads to type-safe nested continuations, which are more appropriate than monads (yet equally expressive and powerful) for imperative languages.
Moreover, a system of checked exceptions composes much better than monads do. And you don't have to believe me. Phil Wadler says it[1] as does Oleg Kiselyov (who's trying to port the same idea back to monadic notation with free monads). This is my own treatment of the subject (which shows how continuations, of which exceptions are a special case, can do monadic composition without monad transformers, and provide type safety through checked exceptions): http://blog.paralleluniverse.co/2015/08/07/scoped-continuations/ http://blog.paralleluniverse.co/2015/08/07/scoped-continuati...
> I truly don't see how you can seriously consider them "identical".
It's not a question of consideration. Wadler and Filinsky proved them to be the same (each from a different direction). See the link to my post above for the exact references.
Still, that's not to say that checked exceptions or Maybe are good approaches. We really don't have data on the subject. It basically comes down to personal preference.
[1]: https://cs.au.dk/~hosc/local/LaSC-7-1-pp39-56.pdf https://cs.au.dk/~hosc/local/LaSC-7-1-pp39-56.pdf
- the_af 11y ago> Fact of the matter is that not enough code has been written with [Maybe/Either] to say that we know how effective they are. Plenty of code has been written. You don't get to claim "fact of the matter" unless it's actually a fact. In reality you seem to be claiming "I don't have enough practical experience with them" which, while entirely respectable, it's a significantly different claim. How much code is "enough code" anyway, according to your standards? > I wouldn't take lessons from Scala. What I'm reading here is: "I don't like your example. I will also pretend to forget other languages which also have Maybe types and exceptions. Also, I'll ignore the part where Maybe/Either are not only used in exceptional 1-in-a-100 situations because it doesn't help my case." > You can silence checked exceptions by doing exactly what you'd be doing to handle Maybe: You need to explicitly handle it. How you handle Maybe and how you silence an exception is different in practice and in mindset. Because Maybe is usually used in expression-oriented languages (something which is somewhat at odds with exceptions), you need to provide a value for the None case, and this forces you to think about which value makes sense (and when you can't find one, it's usually a sign your function was poorly designed). Compare this with the all too common: catch (Exception e) { log.error("Think about this later, if I remember"); } (And if you're already in this dangerous mindset and you must return a value, why, let's pick NULL!) Maybes make this approach tremendously uncomfortable, which is a good thing. Unlike in Java, blindly using something like fromJust is strongly frowned-upon. In any case, you often don't handle Maybes explicitly; it's already handled by rich standard libraries in most languages that advocate the use of Maybe. Compare this to the non-standard chaos that is exception handling ("oops! what will this method do if this other thing throws? will it handle it correctly? I better read the source code"). Which means that in practice both approaches turn out to be quite different. > They just don't work too well with Java's limited effect system of checked exceptions "I don't like your example." > It's not a question of consideration [that exceptions and Maybe/Either are "identical"]. Wadler and Filinsky proved them to be the same (each from a different direction) Sorry, this is too similar to a Turing Tarpit argument. That two systems can be shown to be formally equivalent is very interesting but means little in practice. After all, code with lots of boilerplate and code with little boilerplate can be shown to be equivalent, but it's not identical in practice. > Still, that's not to say that checked exceptions or Maybe are good approaches. We really don't have data on the subject I wish you stopped saying this. Realize that "I don't have experience with this" is not the same as "the world doesn't have experience with this".