Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upall isDigit for empty String should return False #621
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
May 23, 2016
Contributor
All characters in the empty string are digits. Just as all numbers in the empty list are positive. And all eggs in an empty bag are blue.
There is no error here.
|
All characters in the empty string are digits. Just as all numbers in the empty list are positive. And all eggs in an empty bag are blue. There is no error here. |
jvoigtlaender
closed this
May 23, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
galderz
May 23, 2016
Hmmmm, still does not make sense to me. If you don't have anything within a String or List, I can't see how you can make such a truthful statement about the entirety of it.
galderz
commented
May 23, 2016
|
Hmmmm, still does not make sense to me. If you don't have anything within a String or List, I can't see how you can make such a truthful statement about the entirety of it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
galderz
commented
May 23, 2016
|
Any links to better explanations? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
May 23, 2016
Contributor
This is not an Elm or even programming question. It's basic mathematical logic. For example, you may want to read this: http://math.stackexchange.com/questions/202452/why-is-predicate-all-as-in-allset-true-if-the-set-is-empty
But it all really boils down to this:
- I show you an empty bag.
- I ask you: "Are all eggs in this bag blue?"
- You should answer "Yes".
- But if you answer "No", then I will ask you: "So, you think not all eggs in this bag are blue? Can you please show me at least one egg in this bag which is not blue?"
- You won't be able to show me a not-blue egg in that bag, so you will have to concede that indeed, all the eggs that are in that bag (which happen to be exactly zero, but that doesn't matter, it's still all of them) are blue.
Of course, at the same time it is also true that all eggs in that empty bag are red. And that's not a contradiction. It's how mathematical logic, and indeed natural language logic as well, works.
Other than the above explanation, you can certainly google dozens of equivalent explanations for other programming languages. For example, https://issues.scala-lang.org/browse/SI-8587
|
This is not an Elm or even programming question. It's basic mathematical logic. For example, you may want to read this: http://math.stackexchange.com/questions/202452/why-is-predicate-all-as-in-allset-true-if-the-set-is-empty But it all really boils down to this:
Of course, at the same time it is also true that all eggs in that empty bag are red. And that's not a contradiction. It's how mathematical logic, and indeed natural language logic as well, works. Other than the above explanation, you can certainly google dozens of equivalent explanations for other programming languages. For example, https://issues.scala-lang.org/browse/SI-8587 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
May 23, 2016
Contributor
Maybe this will help you most: https://en.wikipedia.org/wiki/Vacuous_truth
|
Maybe this will help you most: https://en.wikipedia.org/wiki/Vacuous_truth |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jarvismartin
Mar 12, 2018
TL;DR: Explicit checks for empty strings, errors, etc. yield more predictable results.
This is probably helpful: http://package.elm-lang.org/packages/elm-lang/core/latest/String#toInt
The important thing to notice is that if you're checking user input, you want to use Return.withDefault.
It provides a default that catches the error state you're looking for, without too much plumbing.
jarvismartin
commented
Mar 12, 2018
|
TL;DR: Explicit checks for empty strings, errors, etc. yield more predictable results. |
galderz commentedMay 23, 2016
Hi, I'm playing around with Elm 0.17 Repl and I've noticed this:
That can't be right, empty String as no digits, it should return False, shouldn't it?