mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +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.
|
||||
##
|
||||
## The exact number type to look for will be inferred from usage. Here's an
|
||||
## example where the `Err` branch matches `Integer Signed64`, which causes this to
|
||||
## parse an [I64] because [I64] is defined as `I64 : Num [ Integer [ Signed64 ] ]`.
|
||||
## The exact number type to look for will be inferred from usage.
|
||||
## In the example below, the usage of I64 in the type signature will require that type instead of (Num *).
|
||||
##
|
||||
## >>> when Str.toNum "12345" is
|
||||
## >>> Ok i64 -> "The I64 was: \(i64)"
|
||||
## >>> Err (ExpectedNum (Integer Signed64)) -> "Not a valid I64!"
|
||||
## >>> strToI64 : Str -> Result I64 [ InvalidNumStr ]*
|
||||
## >>> strToI64 = \inputStr ->
|
||||
## >>> Str.toNum inputStr
|
||||
##
|
||||
## If the string is exactly `"NaN"`, `"∞"`, or `"-∞"`, they will be accepted
|
||||
## 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
|
||||
## advanced options, see [parseNum].
|
||||
## TODO use `InvalidStr` or `ExpectedNum a` error
|
||||
toNum : Str -> Result (Num a) {}
|
||||
toNum : Str -> Result (Num *) [ InvalidNumStr ]*
|
||||
|
||||
## 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.
|
||||
##
|
||||
## The exact number type to look for will be inferred from usage. Here's an
|
||||
## example where the `Err` branch matches `Float Binary64`, which causes this to
|
||||
## parse an [F64] because [F64] is defined as `F64 : Num [ Fraction [ Float64 ] ]`.
|
||||
## The exact number type to look for will be inferred from usage.
|
||||
## In the example below, the usage of Float64 in the type signature will require that type instead of (Num *).
|
||||
##
|
||||
## >>> when Str.parseNum input {} is
|
||||
## >>> Ok { val: f64, rest } -> "The F64 was: \(f64)"
|
||||
## >>> Err (ExpectedNum (Fraction Float64)) -> "Not a valid F64!"
|
||||
## >>> parseFloat64 : Str -> Result { val: Float64, rest: Str } [ InvalidNumStr ]*
|
||||
## >>> Str.parseNum input {}
|
||||
##
|
||||
## If the string begins with `"NaN"`, `"∞"`, and `"-∞"` (which do not represent
|
||||
## [finite](Num.isFinite) numbers), they will be accepted only when parsing
|
||||
## [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:
|
||||
## * 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)
|
||||
}
|
||||
|
||||
/// Str.toNum : Str -> Result (Num a) {}
|
||||
/// Str.toNum : Str -> Result (Num *) [ InvalidNumStr ]*
|
||||
fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
lowlevel_1(symbol, LowLevel::StrToNum, var_store)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue