Qix- / arua-meta

Standards, RFCs and discussion of the Arua language
44 stars 2 forks source link

RFC: Primitive Types and Type Qualifiers #12

Closed Qix- closed 7 years ago

Qix- commented 8 years ago

Arua's primitive types consist of integers (unsigned/signed), floating point numbers, and arrays of those types. To be clear, arrays of types (including arrays of primitives) are their own individual types and are not directly coercible to their primitive counterparts.

Type Qualifiers

All declarations (foo Type) are considered immutable without the mutable type qualifier (foo !Type). As well, all declarations are considered mandatory (cannot be nil) unless they have the optional type qualifier (foo Type?). These qualifiers can be combined (foo !Type?). Type qualifiers do not create or affect any type (they describe individual usages of existing types within a statement, rather than define the type itself).

Implicit Conversions

Implicit Conversions are intuitive and simple in Arua. For a unit with a type Child that is a sub-type of Base (e.g. via a typedef):

row = column Base Child !Base !Child Base? Child? !Base? !Child? nil
Base ✓* ✓* ✓* ✓*
Child ✓* ✓*
!Base
!Child
Base? ✓* ✓* ✓* ✓* ✓* ✓* ✓* ✓* ✓*
Child? ✓* ✓* ✓* ✓* ✓*
!Base?
!Child?

* Only if it's the initial assignment

Optional Qualifiers

Optional qualifiers force a check of nil for all types before they can be referenced.

foo Type? = getFoo()
foo.someMethod() # compilation error

# ---

foo Type? = getFoo()
if foo != nil
    foo.someMethod() # compiles OK

This check honors visibility (#19). Calls into functions check that operate on optional types must be in code paths that have already checked for nil. Unit-public functions always assume such checks have not been made.

pub fn publicFunction(foo Type?)
    privateFunction(foo) # error - privateFunction() argument `bar` is not optional protected

fn privateFunction(bar Type?)
    bar.someMethod() # doesn't check for `nil`
pub fn publicFunction(foo Type?)
    if foo != nil
        privateFunction(foo) # compiles okay

fn privateFunction(bar Type?)
    bar.someMethod() # doesn't check for `nil`

Signed-ness

All signed types (i32, i16, i8, iXX) are Two's Complement representations.

Floating Point

All floating point types (f32, f64, fXX) are IEEE 754 compliant floating point numbers.

Qix- commented 7 years ago

Rejecting this as the type system has been revised a bit. The pieces are the same, but the ways they are semantically represented/used are now different.

For example, mutability is being broadened to mean Does not incur side effects - not just that it doesn't change the object's state. This means no I/O, etc. Routines being evaluated for side effects is now a language feature, as will be described in future RFCs.