improved String.to_nat

This commit is contained in:
HyagoFellipee 2022-05-24 14:11:52 -03:00
parent 4b7417d8f1
commit 85e1c2f101

View File

@ -1,10 +1,8 @@
String.is_nat(s: String): Bool
String.is_nat.aux(s, true)
String.is_nat.aux(s: String, aux: Bool): Bool
case s {
nil : aux
cons:
let is_digit = Bool.and(Char.is_digit(s.head),aux)
String.is_nat.aux(s.tail, is_digit)
String.is_nat(str: String): Bool
case str {
nil: true
cons: case Char.is_digit(str.head) {
true: String.is_nat(str.tail)
false: false
}
}