Questionable
Questionable Types (?)
Questionable Types (?)In Helix, questionable types are used to represent values that might hold one of three states:
- A valid value.
null
(indicating the absence of a value).- An error (indicating an exceptional state).
This feature integrates error handling and null checks directly into the type system, making Helix code concise, robust, and expressive.
Declaring Questionable Types
Declaring Questionable TypesA questionable type is created by appending ?
to a base type. For example:
int?
: A questionable integer.string?
: A questionable string.
Key Behaviors
Key BehaviorsUsing Questionable Types
Using Questionable TypesYou can use a questionable type like a regular variable. If you use it in a context where a non-questionable type is required, Helix implicitly checks its validity:
- If the value is valid, it proceeds.
- If the value is
null
or an error, the program stops with a crash.
Validity Checks
Validity Checks1. Broad Check with ...?
1. Broad Check with ...?Use ...?
to check if a questionable type holds a valid value:
2. Specific Error Detection with in
2. Specific Error Detection with inTo detect specific errors, use the in
keyword:
3. Explicit null
Checks
3. Explicit null ChecksUse == null
or compare directly to null
to detect null states:
Assigning Questionable Types
Assigning Questionable TypesA questionable type can hold one of three states:
- errors can not be assigned directly. Since they are the panicked state of a function.
- They can be assigned as a result of a function call. but not directly.
- refer to Panic for more information.
Using Questionable Types in Functions
Using Questionable Types in FunctionsReturning Questionable Types
Returning Questionable TypesFunctions that may fail or return no value should use questionable types:
Accepting Questionable Arguments
Accepting Questionable ArgumentsFunctions can accept questionable types as arguments and validate them inside:
Practical Examples
Practical ExamplesAdvantages of Questionable Types
Advantages of Questionable TypesCommon Mistakes
Common MistakesSkipping Validity Checks
Skipping Validity ChecksProblem: Using questionable types without validation.
Solution: Always check validity with ...?
before using:
Conclusion
ConclusionQuestionable types (?
) in Helix are a powerful tool for managing nullable and error-prone data. By embedding error and null handling into the type system, Helix enables clean, concise, and safe code. Use ...?
, in
, and error in ...
to validate questionable types and write robust programs.