(module main)

(fn f64_ok () -> (result f64 i32)
  (ok f64 i32 1.5))

(fn f64_err () -> (result f64 i32)
  (err f64 i32 7))

(fn bool_ok () -> (result bool i32)
  (ok bool i32 true))

(fn bool_err () -> (result bool i32)
  (err bool i32 9))

(fn f64_ok_value () -> f64
  (match (f64_ok)
    ((ok value)
      value)
    ((err code)
      0.0)))

(fn f64_err_code () -> i32
  (match (f64_err)
    ((ok value)
      0)
    ((err code)
      code)))

(fn bool_ok_value () -> bool
  (match (bool_ok)
    ((ok value)
      value)
    ((err code)
      false)))

(fn bool_err_code () -> i32
  (match (bool_err)
    ((ok value)
      0)
    ((err code)
      code)))

(fn main () -> i32
  (if (= (f64_ok_value) 1.5)
    (if (= (f64_err_code) 7)
      (if (bool_ok_value)
        (bool_err_code)
        1)
      1)
    1))

(test "result f64 ok constructor and match"
  (= (f64_ok_value) 1.5))

(test "result f64 err constructor and match"
  (= (f64_err_code) 7))

(test "result bool ok constructor and match"
  (bool_ok_value))

(test "result bool err constructor and match"
  (= (bool_err_code) 9))
