[Haskell-cafe] Bool is not...safe?!
jo at durchholz.org
Sat Jul 7 08:17:07 UTC 2018
Am 07.07.2018 um 07:15 schrieb Paul:
> By the way, there are a lot of articles why checked exceptions are bad
> design (more problems than benefit).
That's because exceptions disrupt control flow.
If they're used as an alternative to pattern matching, i.e. thrown only
in tail position and always either fully handled or rethrown unchanged,
then they're fine.
I.e. checked exceptions are bad because they make it easy to construct
bad design. Unchecked exceptions can be abused in the same way but there
seem to be psychological reasons why this isn't done so often.
> More interesting for me is this snippet:
> case (action :: Either err a) of
> Right result -> ...
> Left err -> deal_with err
> Somebody says me that to use Bool in such way is “not safe” because no
> way to know what does “True” returning from “action” mean. Success or
> failure? But with some ADT (Success|Failure) code is more Haskellish and
Terminology N.B.: (Success|Failure) is not an abstract data type (ADT).
It's pretty much the opposite of abstract.
> But is it true? We are talking about semantics, not type-safety because
> type-checker passes both cases (positive branch under False/Failure,
> negative branch under True/Success). But the same with Right/Left:
> nothing says you to use Right for positive and Left for error case. Is
> it true?
There's no good way to use Bool as the type of action, so the point is moot.
Of course you can reconstruct action's type to be a struct consisting of
a Bool, a SuccessResult, and a FailureResult, but that's just awkward so
nobody is doing this.
> Bool is algebra <1, 0, +, *>
Let me repeat: the algebraic and mathematical properties of Bool are
> Problem with Haskell is that it’s imperative and not declarative
Haskell isn't imperative.
I.e. it matches almost none of the definitions for "imperative" that I
have ever seen.
It matches a substantial percentage of the definitions for "declarative"
actually, but not enough of them that I'd instinctively say it is really
declarative - others with a different set of definitions encountered may
> The root of the problem is that imperative nature of Haskell leads to
> missing term “evaluation to something”.
The most compact definition of "imperative" that I have seen is
"computation progresses by applying side effects".
By that definition, the ability to distinguish evaluated and unevaluated
expressions is irrelevant.
> Haskell program is not evaluated
> expression and in the same as in Java or C: it is IO action. But in
> Prolog every piece of code is evaluated to TRUTH or to FALSE. Each
> sentence is a goal which can be achieved and becomes a fact or can not
> be – and becomes lie.
Wrong terminology. Nothing in a computer is a lie.
Prolog works by turning stuff into either tautologies or contradictions.
A lie is something entirely different: a statement that intentionally
contradicts reality. Programming language semantics does not have
intention; programs may have state that matches or contradicts reality,
but take this message which isn't a lie but still does not match any
reality because no sheet of paper with these glyphs ever existed (there
may be in the future if somebody prints this message, but that doesn't
turn this message from a lie into a truth).
Please, get your terminology right. If you keep working with "almost
right" terminology in your head, you will continuously "almost
misunderstand" whatever you read, leading you to conclusions which are
almost right but take a huge amount of effort to clean up. People who
know the concepts and the terminology will find it too tiresome to talk
with you because it is all about educating you (which is not the right
level to talk with a person anyway), and will eventually drop out of
discussions with you; the only persons who talk to you will be those who
happen to have similarly vague ideas, placing you in an echo chamber of
ideas that lead nowhere because everything is subtly wrong.
Just saying. I'm not going to force anything on you - but I find that
this message is entirely about terminology correction and almost nothing
about the topics that really interest you, which means it's been mostly
a waste of time of both of us.
More information about the Haskell-Cafe