Explicit Nullability (T?)
In Wysna, types are non-nullable by default. A variable of type str can never hold none. This eliminates the “billion-dollar mistake” and prevents unexpected null dereference crashes at runtime.
Nullable Types (T?)
Section titled “Nullable Types (T?)”When a value may legitimately be absent, you must append ? to the type annotation. Absent values are represented by the literal keyword none:
# Non-nullable: guaranteed to contain a valid stringlet user: str = "Alice"
# Nullable: can contain either a string or nonelet nickname: str? = noneIf you try to pass nickname into a function that expects str, the compiler rejects it:
Error: Type mismatch. Expected `str`, found `str?`Safe Coalescing (??)
Section titled “Safe Coalescing (??)”Use the ?? operator to provide a fallback default when an optional value is none:
fn get_display_name(username: str, nickname: str?) -> str { # If nickname is none, evaluate to username return nickname ?? username}
fn main() -> unit { print(get_display_name("washo", none)) # prints: washo print(get_display_name("washo", "El Ingeniero")) # prints: El Ingeniero}Unwrapping Optionals with match
Section titled “Unwrapping Optionals with match”To inspect an optional value and access its underlying payload, you can match on Some(v) and None:
fn process_optional(value: str?) -> unit { match value { Some(text) => { print("Value length:", len(text)) }, None => { print("Value was absent") } }}