tj / luna

luna programming language - a small, elegant VM implemented in C
2.45k stars 147 forks source link

Composite types/generics #70

Open glhrmfrts opened 8 years ago

glhrmfrts commented 8 years ago

I just noticed that the parser currently accepts only identifiers as a hash literal key, e.g.:

{hello: "world"}

I think that when this was implemented it was meant to be temporary, but since Luna is planned to be a statically typed language I think we need to define a syntax for generic types.

vendethiel commented 8 years ago

please, use always-matching brackets, not c++-style c++

glhrmfrts commented 8 years ago

@vendethiel sorry, but can you give an example?

vendethiel commented 8 years ago

Sorry, i meant <>, which are not always matched... Making parsing harder.

glhrmfrts commented 8 years ago

Yeah I don't see much sense in that being unmatched. Anyway, this syntax is very ugly to me:

map<string, int>{
  "number": 2
}

But i can't think of anything else.

vendethiel commented 8 years ago

"Being unmatched" => they are when you use it as comparison operators.

map[string, int]{...} map!(string, int){...} (d-style)

aisk commented 8 years ago

I think if luna have a type inference, the syntax will be cool:

{"foo": "bar"}    => map<string, string>
{"foo": "bar", "alist": [1, 2, 3]}    => map<string, interable<any>>
{"foo": "bar", "truth": 42}    => map<string, any>

But I think this will be a large project 😅

vendethiel commented 8 years ago

very, very large indeed. And can be very surprising – see Scala.

aisk commented 8 years ago

@vendethiel Yes, may be this is not luna's target simple, elegant, explicit haha

glhrmfrts commented 8 years ago

@vendethiel Oh I see now :p But maybe <> would be easier than square brackets (because of subscript), unless it's context-dependent and we do some semantic analysis later.

glhrmfrts commented 8 years ago

@aisk Maybe it's possible to a large project achieve simplicity? lol

aisk commented 8 years ago

@glhrmfrts I think it's not just too complex to implement, but with this design luna's type system may be more complex, and make it more hard too learn and use.

glhrmfrts commented 8 years ago

Indeed, a more strict type system might be good for both sides.