gorillascript icon indicating copy to clipboard operation
gorillascript copied to clipboard

Named interfaces

Open ckknight opened this issue 12 years ago • 0 comments

Currently, one can specify specific object types as so:

let f(o as { alpha: String, bravo: Number }) ->

Which can get unwieldy if the object is too complex or if there is practically any repetition in code.

Instead, I'm proposing the following syntax:

interface Thing = {
  alpha: String
  bravo: Number
}
let f(o as Thing) ->

In the previous example, Thing would not exist at runtime and merely be a compile-time alias like C's typedef. One would be able to alias any type with a name, including functions or other interfaces or basically anything that already works in the type system.

Also, having generic support would be nice:

interface Box<T> = {
  get: -> T
  set: T -> T
}
let f(o as Box<Number>) ->
let g(o as Box) -> // the T in Box<T> represents the "any" type here, since unspecified.

ckknight avatar Jul 18 '13 01:07 ckknight