ozra / onyx-lang

The Onyx Programming Language
Other
96 stars 5 forks source link

Feature request: Heterogeneous arrays #29

Closed stugol closed 8 years ago

stugol commented 8 years ago

In Crystal, tuples are heterogenous, but cannot be extended or modified at runtime; while Arrays are extensible but homogenous. Ideally:

my-array = ["", 2, nil]
my-array << false
puts my-array.class             -- should NOT be String | Int | Nil | Bool,
                                -- but rather [String, Int, Nil, Bool], like a tuple

Come to think of it, might be better to turn this on its head: keep arrays homogenous, but make tuples editable:

my-tuple = {"", 2, nil}
my-tuple << false
puts my-tuple.class             -- {String, Int, Nil, Bool}
ozra commented 8 years ago

This is pretty much an impossible feat. It mixes the domains of static type resolution and run time value resolution. For type to be certain - in a certain position - the container cannot be dynamically extended, because then there cannot be a guarantee that the position actually holds a value of the promised type. And hence, strong type checking crumbles into a pile of doo doo.

Why would you possibly need it?

stugol commented 8 years ago

Relaxed typing here would probably solve this.

Also an example.

ozra commented 8 years ago

Does that issue suffice, we're on to something there, maybe this can be closed?

stugol commented 8 years ago

Sure, it should be a decent alternative. And more useful.