slovo/docs/language/examples/speculative/option-result.slo
2026-05-22 08:38:43 +02:00

28 lines
786 B
Plaintext

; status: design/speculative
; Follow-up option/result behavior beyond promoted i32 constructors, value
; flow, tag observation, and explicit trap-based payload extraction.
; Pattern matching, mapping, equality, printing, strings, non-i32 payloads,
; nested option/result values, arrays or structs containing option/results, and
; user-catchable exceptions remain speculative.
(module option_result)
(fn maybe_name ((enabled bool)) -> (option string)
(if enabled
(some string "Slovo")
(none string)))
(fn describe ((value (option i32))) -> string
(match value
((some number) "some")
((none) "none")))
(fn bool_option () -> (option bool)
(some bool true))
(fn string_error () -> (result i32 string)
(err i32 string "not found"))
(fn main () -> i32
0)