Skip to content

Latest commit

 

History

History
78 lines (54 loc) · 3.06 KB

types.md

File metadata and controls

78 lines (54 loc) · 3.06 KB

Type system

I want this language to have a strong static type system, I don't want implicit conversions everywhere, like C has, that's a huge cause of many bugs. We know this kind of type system can alleviate these bugs. I don't think it's any coincidence that other newer languages are taking this route.

It should be possible to query types for various information, like upper and lower values allowed, it's type name, an enumeration's value as a string. This would be handled in a similar way to Ada's attribute system, Ada uses the apostrophe, e.g.

Lower : constant := T'First;

I was considering using the question mark instead, to denot this query, as that makes sense, but it's harder to read, as can be seen here.

s := a?upper
S := A?Upper

Maybe adding spacing would work?

s := a? upper
S := A? Upper
s := a ?upper
S := A ?Upper

Other languages that implement this kind of reflection just use the dot and make it look more like an operation or a method call. As can be seen in Jai here.

printf("  name: %s\n", it.name);

Or in Odin.

import "core:reflect"
...
names := reflect.struct_field_names(id);

Other languages do use the question mark for testing nullable or option types. Swift is one example.

Go uses it for optional parameter.

What other options are there? The apostrophe would force the lexical analyser of the compiler to have multiple look ahead and push back in the case of characters, especially Unicode.

s := a.upper  // Really should look different to normal operations.
s := a#upper  // Similar to ?, harder to read.
s := a^upper  // Pascal's pointer dereference.
s := a`upper  // Lisp's back tick?
s := a~upper  // Something different altogether?
s := a:upper  // Not too bad.
s := a%upper  // Hard to read.

Built in types

There needs to be convenience types available, but the emphasis should be in defining your own types. These can be integer and float (or real). In addition to these, there should be a boolean type.

As mentioned in the arrays document, it would be useful to be able to specify SIMD types, depending on which version, AVX, SSE4.2, etc. depends on how many registers you get access to and what bit size they are. This is definitely a a future feature once the basics of the language are defined.

Notes

  • Variables/constants should be initialised to a known value.
  • Variables/constants should be non-mutable by default.
  • Dispatching on return types is very useful and an underrated feature of Ada.

References/Pointers

Unique types

  • Some types should only be used once, i.e. to define the type of a memory mapped register.
  • Is this a thing anywhere else?