-
Notifications
You must be signed in to change notification settings - Fork 44
Conversation
@@ -0,0 +1,48 @@ | |||
open Belt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add Tuples.re also to the TypeScript example folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below.
@@ -222,6 +226,8 @@ let rec converterIsIdentity = (~toJS, converter) => | |||
} | |||
|
|||
| RecordC(_) => false | |||
| TupleC(innerTypesC) => | |||
innerTypesC |> List.for_all(converterIsIdentity(~toJS)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly the same as the ObjectC
case above, but didn't use the OptionC
switch because I didn't think it was necessary (doesn't that case get process naturally when the recursion continues?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option has no special role here, while it does for objects. So this is perfect.
| Ttuple(listExp) => | ||
let innerTypesTranslation = | ||
listExp |> translateTypeExprs_(~language, ~typeVarsGen, ~typeEnv); | ||
let innerTypes = innerTypesTranslation |> List.map(({typ, _}) => typ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very inspired on the Tconstr(path, typeParams, _)
case below.
src/EmitTyp.re
Outdated
"[" | ||
++ ( | ||
innerTypes | ||
|> List.map(typ => typ |> renderTyp(~language, ~indent, ~inFunType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should tuples be emitted like immutable arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Itβs a good question. Theyβre immutable on the Reason side so Iβd say yes.
Nit: typ => typ |> can be omitted: curry.
Also, TS has to is peculiar about naming types. Worth adding the examples. It might dislike the β[...]β for non-basic types.
Immutable arrays would get you out of that notation anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome.
A couple of small comments inline.
src/EmitTyp.re
Outdated
"[" | ||
++ ( | ||
innerTypes | ||
|> List.map(typ => typ |> renderTyp(~language, ~indent, ~inFunType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Itβs a good question. Theyβre immutable on the Reason side so Iβd say yes.
Nit: typ => typ |> can be omitted: curry.
Also, TS has to is peculiar about naming types. Worth adding the examples. It might dislike the β[...]β for non-basic types.
Immutable arrays would get you out of that notation anyway.
@@ -0,0 +1,48 @@ | |||
open Belt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below.
@@ -222,6 +226,8 @@ let rec converterIsIdentity = (~toJS, converter) => | |||
} | |||
|
|||
| RecordC(_) => false | |||
| TupleC(innerTypesC) => | |||
innerTypesC |> List.for_all(converterIsIdentity(~toJS)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option has no special role here, while it does for objects. So this is perfect.
@jchavarri another question, more like an afterthought is: how much can we re-use that exists already? |
Thanks for the review! I have added the TS tests, and removed the unneeded lambda with
I have done a bit of research, and immutable tuples seem to have very bad support at the moment in both Flow and TypeScript. In Flow, there is no way to mark a tuple or its inner types as immutable. In TypeScript, wrapping the tuple with let tuple: Readonly<[string, number]> = ['text', 3];
tuple[0] = 'new text'; // TS says: "All good!"
tuple.shift(); // Can remove elements from the tuple, even if it's read-only
let a: string = tuple[0]; // Type checks, but it'll be a number at runtime I don't really understand the purpose of Considering this, I wonder if it's more appropriate to just leave tuples as they are, just to make more explicit they are mutable, to reflect better these limitations.
I thought about this. I'm not sure there are many things to reuse. At the type definition level, TS syntax for tuples ( At the converter levels, arrays and tuples are different, with the first using So in practice there seem to be different constraints for both cases, but I could explore trying to unify them more if you think it's worth it.
I added the The type
Do you have any pointers? I think in this case Thanks again! |
Thanks for digging, this is great info! OK so it looks like immutability for tuples falls into the high investment low return category, and can be dropped.
|
Wrong guess. You've handled the code for checking what's opaque. |
OK it was not far off. It's this line:
meaning that any other compound of a tuple than those would be considered opaque. So pre-existing. |
@cristianoc Done! π |
So good. Thank you so much for this. |
The issue is strongly correlated with Type Expansion mentioned in #70. So it makes sense to handle all of that together. |
Fixes #68.
This was way easier than I expected, so I guess there must be many things missing π I'll add some inline comments below.
Side note: I find the codebase to be really beautiful β¨ and I'm quite enjoying its discovery. What a delight to see how building on top of recursive types can lead to such a modular architecture!!