Stream: beginners

Topic: Pattern matching tuples of number literals


view this post on Zulip Tom Hill (May 16 2025 at 14:29):

Hi! Another question from me...

Should pattern matching on a (U64, U64) tuple like below work:

rebase : { input_base : U64, output_base : U64, digits : List U64 } -> Result (List U64) _
rebase = |{ input_base, output_base, digits }|
    when (input_base, output_base) is
        (0, _) -> Err(InvalidInputBase)
        (1, _) -> Err(InvalidInputBase)
        (_, 0) -> Err(InvalidOutputBase)
        (_, 1) -> Err(InvalidOutputBase)
        (in, out) if in == out -> Ok(digits)
        _ -> rebase_to_10(input_base, digits) |> Result.map_ok(|number| rebase_from_10(output_base, number))

When I pass an input { input_base: 0, output_base: 10, digits: [] } to the rebase function, it returns a value from the final branch rather than an Err(InvalidInputBase) from the (0, _) branch as I would expect.

view this post on Zulip Anton (May 16 2025 at 14:31):

This is indeed a known issue #5530


Last updated: Jul 06 2025 at 12:14 UTC