jamiebuilds / ghost-lang

:ghost: A friendly little language for you and me.
302 stars 10 forks source link

Tuple types #13

Closed aleclarson closed 6 years ago

aleclarson commented 6 years ago

I assume it's just:

type Foo = [Number, String]

let foo: Foo = [1, 'hi']
jamiebuilds commented 6 years ago

I don't have tuples in the language because lightweight records are better, I don't think it needs a type syntax.

aleclarson commented 6 years ago

Is there no concept of an argument list? Or would that be a record, too?

jamiebuilds commented 6 years ago

In the case of:

fn (...rest) {}

rest is a fixed length array with the type Array<T> where T is the union of all the types of values in rest

aleclarson commented 6 years ago

Clobbering the order would remove type-safety from rest-then-spread-call.

type Foo = fn (a: number, b: string): number
type Bar = fn (a: string, b: number): number

// Are the type declarations are required here?
let bar: Bar = fn (...args) { 1 }
let foo: Foo = fn (...args) {
  bar(...args) // no compiler error, yet [number, string] and [string, number] are incompatible
}
jamiebuilds commented 6 years ago

Well there would be compiler errors because Number | String cannot flow into Number or String

aleclarson commented 6 years ago

So rest-then-spread is not possible? If so, what's the workaround?