Kartik Agaram
Edward de Jong / Beads Project
03/03/2020, 5:25 AMKartik Agaram
Martin
03/03/2020, 10:12 AMEdward de Jong / Beads Project
03/03/2020, 8:12 PMMartin
03/03/2020, 9:44 PMDoug Moen
03/04/2020, 6:21 AMhead
returns the first element of a list, and has type [a] -> a
. But wait, what does head
return if the list is empty? There's no error condition encoded in the result type. Well actually, the program aborts. This problem is everywhere, since case expressions are not required to enumerate all of the possible cases. A sound type system ensures that the program "can't go wrong", and Haskell doesn't manage that.
Edward says Beads is a robust language where all functions are total, which is more ambitious than Haskell. Apparently Beads has a sound type system. That might account for the extra complexity in the boolean type.Edward de Jong / Beads Project
03/04/2020, 9:47 AMMartin
03/04/2020, 3:41 PMKartik Agaram
head
.Kartik Agaram
undefined
if I'm interpreting you correctly. These are not good ideas.
Booleans have 2 states. Variables that need more than two states are absolutely a good idea. They shouldn't use booleans.
In general, the problem of type modeling is to have a Goldilocks number of states for each variable: not too many so some states are rare and programmers don't test for them, and not too few so programmers can't test for some. All this has absolutely nothing to do with booleans.Doug Moen
03/04/2020, 4:16 PMKartik Agaram
Doug Moen
03/04/2020, 4:46 PMEdward de Jong / Beads Project
03/05/2020, 2:31 AMKartik Agaram
Kartik Agaram
Optional<Boolean>
. The nice thing about it is that it's impossible to forget about the third state, a problem JavaScript has in spades.Edward de Jong / Beads Project
03/05/2020, 5:12 AMval = sqrt(-1) < 0
, then the result is neither true
, nor false
, nor undefined
, but as Excel would calculate it, #ERROR
. There is no undefined or missing quantity, but rather the operation is erroneous. This is the fourth state which is necessary to be able to store. Perhaps your program will halt on an error or undefined quantity in debug mode, but in production may propagate the error value (as does Excel) so that it never crashes. People see the red ERROR
cells quickly, and the propagation effect means that all derived quantities based on the original error value are also flagged. This is of great value in long chains of dependencies. It is neither excessive nor imprecise. In fact it is more precise because no information is being destroyed or made up. That a boolean value would take 4 bits instead of 2 to store is a trivial additional cost. There is no additional cost to have the fourth state given that you needed at least 2 bits to store it anyway.Kartik Agaram
Stefan
03/05/2020, 11:37 AMEdward de Jong / Beads Project
03/07/2020, 10:46 PMKartik Agaram
undefined
as much as possible, which entirely defeats the point.
Here's an example of a major domain where you absolutely want 2-state booleans: Boolean satisfiability (SAT) solvers. Adding extra states here would make tractable problems intractable.
(Apologies for the harshness of my previous comment in this thread. I plead sleep deprivation.)Edward de Jong / Beads Project
03/07/2020, 11:13 PM