A type system for haku #110
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A type system would allow us to have more clear error messages, as well as make the language easier to analyse for IDE-style features.
This type system would not be visible to outside users, but rather use full program type inference to point out mistakes ahead of time without you having to annotate anything.
I've never written a type system with constraint-based type inference like this before, so it will probably require a lot of research work to be pulled off. I also worry the error messages may end up not being clear enough for users to understand, but we'll see how that goes.
A taxonomy of types in haku:
[]
- Nothingboolean
- Represented using the special tagsTrue
andFalse
number
- 32-bit floatTag
- Literally just the tagTag
. Each tag is its own type.n t
- Static list ofn
xt
elements. Result of[]
literals.2 number
,3 number
,4 number
replacevec
andrgba
list t
- Dynamic list of any number oft
elements\a -> r
- Function accepting the argumenta
and returning the valuer
. There can be more than one argument, but there's always at least one. If that argument is irrelevant, the type is\[] -> t
.{ A = t }
- Record. Acts like a function which can be called withA
as its argument to get a value of typet
.act
- An action the brush can take. A reticle, scribble, or a list containing any amount of scribbles.reticle
- A latent input from the user—such as thedotter
, theselectRect
, or theeditRect
.scribble
- An output from the brush—such as thestroke
orfill
.shape
- A shape that can be scribbled.line
- A line segment.rect
- An axis-aligned rectangle.circle
- A circle with a position and radius.Subtyping relationships:
One extra typing rule that I'm not sure how to include here: I believe it should be possible to pass
t
wherever a function directly acceptsn t
, coercing it into a1 t
. This is so that we can make math functions like+
,sin
, etc. acceptn number
as an argument, and therefore work with arbitrarily-sized vectors andrgba
.Writing this rule down as
t <: 1 t
doesn't work, because it would result in infinite recursion—because ift <: 1 t
, then also1 t <: 1 (1 t)
, so on and so forth,A note on
n t
: Indexing is still done via theindex
function, but elements 0–3 can be accessed alternatively by using function call syntax with the tagsX
,Y
,Z
,W
, orR
,G
,B
, andA
. This also opens a path to swizzling in the future (but I don't want it in the MVP.)Example:
vec.X
. This replaces thevecX vec
andrgbaR
set of functions.