Skip to content
Auto edited this page May 9, 2022 · 8 revisions

Nullable Types and Typed Null.

null, nil, ø is a falsey keyword / constant, which can be avoided with optional typing

Vulgarly, unknown is a well defined null, whereas undefined is an ill defined null.

Nullable Types

All types can be expressed to be optional, that is their values are allowed to be missing empty or in old terms: null.

class contact {
 name required
 maybe email
 phone optional
}

The optionally is really part of the variables (and parameters), but for internal propagation all types have an internal flag nullable.

Since this is an ubiquitously used paradigm, it deserves its own sigil:

class contact {
 name 
 email?
 phone?
}

It makes the code more readable and behave like swift, kotlin and dart; avoiding the overly verbose Optional<>, Some<>, Maybe … syntax of rust and haskell.

Typed Null

It is important that (except in unsafe code) null is a keyword, not an object.

So Person? may_be_missing = null; is just syntactic sugar for Person? may_be_missing = Person.null.

In English we say John is a missing person, not John is a missing.

Instead of the swifty if let x_found=maybe_x {} syntax, Angle uses if truthy {} control flow analysis:

String? possibly_email=some_func()
if possibly_email {
   print(may_be_missing.size) // surely not missing
}

Conversely to test if an optional value may_be_missing is empty, check with

if may_be_missing empty {}
if may_be_missing absent {}
if may_be_missing missing {}
if may_be_missing unknown {}
if may_be_missing undefined {}
if not may_be_missing {} 

!!! there is never any need to check for combinations of these keywords: if may_be_missing unknown or may_be_missing undefined {}

Instead, they are either synonymous or strict sub concepts, in any case one keyword always captures all destitute cases.

The empty keyword really checks missing or empty. Todo: It is redundant to the truthiness check if not may_be_missing {}

In addition to the swift-like optionality operator '?' cat{name:string?} angle has a required operator '!' cat{name:string!} which is different to the default cat{name:string} in the sense that … <>

null types / typed nulls can be represented via smart pointers.

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally