<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>So, the problem is that test of emptiness does not force you to
something right. And possible errors are:</p>
<blockquote><tt>if empty:</tt><br>
<tt> # do if NOT empty - BUG!</tt><br>
<tt>else:</tt><br>
<tt> # do if EMPTY - BUG TOO!</tt><br>
<br>
<tt>or</tt><br>
<br>
<tt># do if NOT empty - BUG!</tt><br>
<tt>if NOT empty:</tt><br>
<tt> # now nothing or old "do if NOT EMPTY"</tt><br>
</blockquote>
<br>
OK, I understand it. But how is it related to Booleans? :) Sure, if
you use Maybe or Either you are forced with nature of ">>=":
it cuts off incorrect branches. With if-then - it does not. But it's
not related to Bool: Bool is result for predicates. Maybe/Either
forces you with magic operation ">>=" (which is hidden by
do-sugar). Bool does not force you - right. But it's problem of
Haskell implementation. For example, Prolog "forces" you:<br>
<br>
Haskell forces you in monad "do":<br>
do<br>
someInt <- someMaybe<br>
-- will not be executed if someMaybe is Nothing<br>
<br>
Prolog forces you too but on success/fail (Boolean?):<br>
someGoal, anotherGoal % anotherGoal will not be executed if
someGoal is False<br>
<br>
Haskell adds only "bool" function which is close to ">>=" in
terms of it hides semantic of right bool's processing, avoid those
possible errors. If you will use "bool" anywhere when you use Bool
as result - all will be fine, or? Sure, you can move "head" usage
out of "bool" but you will get empty "bool"s argument. So, IMHO
examples of problem with booleans is not related to Bool type at
whole, but related to problem that Bool has kind * but not * -> *
to be processed in monadic style (and to has needed ">>="
semantic to force you).<br>
<br>
OK, but original article was not about Haskell's monads, but about
Bool in general :) Also what I can't understand: if we will think
in such manner does it mean that "if..test" construct is
"boring"/"blindness" (excuse my English:) at whole? And all
predicates must be removed from the language? What will happen to
`filter` function without predicates? And no way to avoid "if..else"
construct and predicates functions.<br>
<br>
As for me, this question is related to static-types fanaticism and
"How many angels could dance on the head of a pin". Example with
"head" is totally incorrect - it can deconstruct list and no need to
predicate function. But what I should do with isSpace, isLower, etc?
How to use predicates at whole? :) To map a -> Bool to a
-> Maybe a ?<br>
What about function which returns IO Bool? Action which can ends
with non-critical failure (and need optionally logging, for example)
?<br>
<br>
<br>
<div class="moz-cite-prefix">05.07.2018 17:27, Stefan Monnier wrote:<br>
</div>
<blockquote type="cite"
cite="mid:jwv7em9hij0.fsf-monnier+gmane.comp.lang.haskell.cafe@gnu.org">
<blockquote type="cite">
<pre wrap="">There is an opinion that Bool type has problems. It's "dangerous", because
it's not good to be used as flag for success/fail result. I read this post:
<a class="moz-txt-link-freetext" href="https://existentialtype.wordpress.com/2011/03/15/boolean-blindness/">https://existentialtype.wordpress.com/2011/03/15/boolean-blindness/</a> and was
shocked. How popular is such opinion? Is it true, that bool is "bad" type?
</pre>
</blockquote>
<pre wrap="">
To me the argument boils down to the `head` case mentioned by Alex.
Most programming languages force you to write code like
if List.empty l then
...
else
... x = List.head l ...
where the problem is that the fact that the List.head call will find the
list non-empty is not obvious (in the sense that it requires reasoning).
In contrast
case l
| nil => ...
| cons x xs => ...
makes it trivially obvious that `x` is extracted from a non-empty list
without any reasoning needed at all.
Stefan
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
Only members subscribed via the mailman list are allowed to post.</pre>
</blockquote>
<br>
</body>
</html>