mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
consistent result type signatures
This commit is contained in:
parent
d6ab0b6aa4
commit
58f3559c98
2 changed files with 12 additions and 16 deletions
|
@ -433,37 +433,33 @@ toDec : Str -> Result Dec [ InvalidDec ]*
|
||||||
|
|
||||||
## If the string represents a valid number, return that number.
|
## If the string represents a valid number, return that number.
|
||||||
##
|
##
|
||||||
## The exact number type to look for will be inferred from usage. Here's an
|
## The exact number type to look for will be inferred from usage.
|
||||||
## example where the `Err` branch matches `Integer Signed64`, which causes this to
|
## In the example below, the usage of I64 in the type signature will require that type instead of (Num *).
|
||||||
## parse an [I64] because [I64] is defined as `I64 : Num [ Integer [ Signed64 ] ]`.
|
|
||||||
##
|
##
|
||||||
## >>> when Str.toNum "12345" is
|
## >>> strToI64 : Str -> Result I64 [ InvalidNumStr ]*
|
||||||
## >>> Ok i64 -> "The I64 was: \(i64)"
|
## >>> strToI64 = \inputStr ->
|
||||||
## >>> Err (ExpectedNum (Integer Signed64)) -> "Not a valid I64!"
|
## >>> Str.toNum inputStr
|
||||||
##
|
##
|
||||||
## If the string is exactly `"NaN"`, `"∞"`, or `"-∞"`, they will be accepted
|
## If the string is exactly `"NaN"`, `"∞"`, or `"-∞"`, they will be accepted
|
||||||
## only when converting to [F64] or [F32] numbers, and will be translated accordingly.
|
## only when converting to [F64] or [F32] numbers, and will be translated accordingly.
|
||||||
##
|
##
|
||||||
## This never accepts numbers with underscores or commas in them. For more
|
## This never accepts numbers with underscores or commas in them. For more
|
||||||
## advanced options, see [parseNum].
|
## advanced options, see [parseNum].
|
||||||
## TODO use `InvalidStr` or `ExpectedNum a` error
|
toNum : Str -> Result (Num *) [ InvalidNumStr ]*
|
||||||
toNum : Str -> Result (Num a) {}
|
|
||||||
|
|
||||||
## If the string begins with an [Int] or a [finite](Num.isFinite) [Frac], return
|
## If the string begins with an [Int] or a [finite](Num.isFinite) [Frac], return
|
||||||
## that number along with the rest of the string after it.
|
## that number along with the rest of the string after it.
|
||||||
##
|
##
|
||||||
## The exact number type to look for will be inferred from usage. Here's an
|
## The exact number type to look for will be inferred from usage.
|
||||||
## example where the `Err` branch matches `Float Binary64`, which causes this to
|
## In the example below, the usage of Float64 in the type signature will require that type instead of (Num *).
|
||||||
## parse an [F64] because [F64] is defined as `F64 : Num [ Fraction [ Float64 ] ]`.
|
|
||||||
##
|
##
|
||||||
## >>> when Str.parseNum input {} is
|
## >>> parseFloat64 : Str -> Result { val: Float64, rest: Str } [ InvalidNumStr ]*
|
||||||
## >>> Ok { val: f64, rest } -> "The F64 was: \(f64)"
|
## >>> Str.parseNum input {}
|
||||||
## >>> Err (ExpectedNum (Fraction Float64)) -> "Not a valid F64!"
|
|
||||||
##
|
##
|
||||||
## If the string begins with `"NaN"`, `"∞"`, and `"-∞"` (which do not represent
|
## If the string begins with `"NaN"`, `"∞"`, and `"-∞"` (which do not represent
|
||||||
## [finite](Num.isFinite) numbers), they will be accepted only when parsing
|
## [finite](Num.isFinite) numbers), they will be accepted only when parsing
|
||||||
## [F64] or [F32] numbers, and translated accordingly.
|
## [F64] or [F32] numbers, and translated accordingly.
|
||||||
# parseNum : Str, NumParseConfig -> Result { val : Num a, rest : Str } [ ExpectedNum a ]*
|
# parseNum : Str, NumParseConfig -> Result { val : Num *, rest : Str } [ InvalidNumStr ]*
|
||||||
|
|
||||||
## Notes:
|
## Notes:
|
||||||
## * You can allow a decimal mark for integers; they'll only parse if the numbers after it are all 0.
|
## * You can allow a decimal mark for integers; they'll only parse if the numbers after it are all 0.
|
||||||
|
|
|
@ -1324,7 +1324,7 @@ fn str_trim_right(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
lowlevel_1(symbol, LowLevel::StrTrimRight, var_store)
|
lowlevel_1(symbol, LowLevel::StrTrimRight, var_store)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Str.toNum : Str -> Result (Num a) {}
|
/// Str.toNum : Str -> Result (Num *) [ InvalidNumStr ]*
|
||||||
fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
lowlevel_1(symbol, LowLevel::StrToNum, var_store)
|
lowlevel_1(symbol, LowLevel::StrToNum, var_store)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue