-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start working on type ascriptions #803
Conversation
could you give an example? I'm not sure I understand |
So, basically: (a @: Type, b @: Type) -> ... Gets compiled to: (function(a : Type, b : Type){ ... }) Is the idea to support things like TypeScript or Flow? |
Yes, indeed. I'll make this clearer. |
Ah. I'm not particularly fond of the I like the idea of compiling to TS/Flow though :3 |
Right? |
oh, I see now. yea, I like the idea of compiling to TS/flow. could this work? fn = (:a Type, :b Number) -> |
It'd make the lexer a bit more complex, which I'm not too fond of. But I'm open to opinions. |
An alternative might be using the same symbol Clojure uses to declare types. It's reusing a symbol, but I don't think that's an issue for argument names: foo = (a ^Type, b ^Another-Type) ^ReturnType -> ...
foo = (a ^Type = ^clone) -> ... |
Yeah, but it's currently parsed as an infix MATH (power) :/ |
At least, the fact our unary clone got changed to |
is there any interest in making some breaking changes to free up operators like also, even the Livescript homepage seemingly uses finally, there already seems to be some discussion on removing duplicated/etc. functionality: peace |
We can change the docs, that's very minor. It currently just mimics Haskell's syntax :-). You're free to ping those issues to try and get some tractions ;-). |
Seems to be a syntax error - maybe we could just support the syntax for function definitions? |
Problem is just the lexer's complexity. We need to resort to per-nest flag (or something) to parse correctly |
Urgh, https://github.com/gkz/LiveScript/blob/master/test/cs-classes.ls#L289 doesn't parse correctly. Obviously. I guess I need to change the regexp to |
ok, if you don't like the atom syntax, what about c++ syntax? lala = (a<Type>, b<Number> = 3) -> ... |
|
Arrow functions are fine and dandy but what aboot braceless function declarations?
C++ style looks best to me. What do you guys think about type contracts like in contracts.coffee or elm? |
I really don't like parenless function definitions, but anyway, all the signatures will look the same. |
I vote for
is more obvious than that:
|
agreed
|
Unfortunately |
How about declaring the function type in a separate line? add :: (Number, Number) -> Number
add = (a, b) ->
a + b I think the other syntax (defining the type in the same line as declaring the function) creates too much visual clutter, and it just doesn't go with LiveScript's terse syntax, but that might be a matter of taste. |
@AriaMinaei may be as alternative, but if you have a lot of arguments, inline declaration will be easier to read. add :: (
number
number
string
boolean
Object
Date
string[]
) -> number
add = (
foo
bar
test
test2
abc
def
zyx
) ->
a + b In this case I can't say immediately what type does have add = (
:foo number
:bar number
:test string
:test2 boolean
:abc Object
:def Date
:zyx string[]
): number ->
a + b |
@unclechu Correct, but how many functions would have that many arguments? A function invocation with more than five or six arguments would be a bit unreadable, unless the arguments are named (through a config object). Also, writing type annotations in the same line as function declaration makes even simple functions like this overly verbose. I'm not even sure if that is a matter of taste. |
I love this one style of type declaration:
@unclechu I think we should not pass more than 4 or 5 arguments, in this case we should use data structures (Array, Object). Look:
|
@vendethiel Status? |
@isiahmeadows still undecided on which token. Overloading |
Maybe JavaScript types in TypeScript ? |
@thelambdaparty I really dislike JSDoc type annotations. They are almost a joke in their verbosity. |
As is TypeScript. |
@rightfold To be honest, Java's type system are better than JSDoc annotations in my opinion. And I really don't like Java. The only thing they're worth using for are for external API documentation, and even that's disputable. I wasn't comparing them to powerful type systems like Haskell's. |
Who said anything about Java? |
I was drawing a comparison to clarify what I meant. Basically, I feel JSDoc On Mon, Feb 22, 2016, 07:49 I moved to Bitbucket [email protected]
|
So many options...
(I really like the syntax of the last two, reminds me of nim's pragmas) |
I'm okay with any of those except the ones with ampersands (I would On Tue, Feb 23, 2016, 06:30 Christian Ferraz Lemos de Sousa <
|
Do they need to be non-valid js identifiers (like : or ^ etc.)? If they can be anything, how about
|
I would prefer ASCII symbols to denote types, BTW. And preferably, yes, On Sat, Feb 27, 2016, 19:09 Kay Plößer [email protected] wrote:
|
I have the § key on my keyboard and I would have suggested it also but the us kbd does not have the key. I always thought it was ascii, but upon looking - alas it is not - I guess it was one of the iso standards. I'm also ok with whatever cept for ampersands. I suppose the clearest to my eyes is the |
I have no such key, and many of us |
sorry, that wasn't the point.
|
I know this is a closed PR, but since @dk00 is still linking to it, it seems useful as a repository for bikeshed suggestions. Here's mine:
Advantage of this syntax over most of the above: it already parses into an AST, and (Edit: made some some overconfident assertions there, huh?) |
I'm not sure what that 2nd line describes? The |
Ascriptions for variable declaration. |
is |
|
Isn't this ambiguous with |
Gah, yes, you're right! Righto, that's what I get for tossing off half-baked thoughts in passing. |
It might be better, at least at first, to only allow type ascription when using declarators ( |
Another soft ball in the air: A method I'm biased towards (used in my own lang) is that types are required to be Capitalized, while all value identifiers are required to be initial lowercase: Too bad @kay-is suggestion of The Haskellish way posed earlier in the issue is a good bet too, and when non-clashing symbology can be figured out - both the inline- and pre- typedecl would be awesome imo. |
Well, there's always the solution of writing the type signature before the object itself, and not inline. That'd remove a good chunk of ambiguities. |
What is the status of this ? |
Exactly what it looks like. There's the occasional idea being tossed around in #999, if you feel like helping out. |
I'll take a look at that issue. |
I would like everyone's input on this: the syntax, what we're compiling to, etc.
The idea is to compile down to TS or flow-compatible stuff