-
Notifications
You must be signed in to change notification settings - Fork 438
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
[WIP] Generate flow annotations #780
Conversation
@@ -0,0 +1,117 @@ | |||
open Types | |||
|
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.
a minor style issue, in general, open is not encouraged, especially for modules like Types
which is an internal module
b99d55c
to
fa7546a
Compare
I finally got more time, and want to finish this. But I can't figure out one thing. I'm not sure how this thing is called, maybe type variable scope. Check the following example. Is there a way to know where type variable should be added?
In the |
hi @pvolok does flow support higher rank polymorhism? here you might hit type system mismatch: some types are not expressible in OCaml, some are not expressible in Flow? |
If I understand correctly what higher rank polymorphism is, then yes, flow supports it. I read more about it and it looks like the following is not possible in ocaml: let fn (same : 'a . 'a -> 'a -> unit) =
same 1 2; (* OK *)
same 'a' 'b'; (* OK *)
same 1 '2'; (* ERROR: int and char are incompatible *) So I attach poly types to the most outer function. Like this: val fn: 'a -> ('b -> 'b) -> unit Flow declare var fn: <A, B>(p1: A, p2: (p: B) => B) => void; |
you are right, If I understand correctly what higher rank polymorphism is, then yes, flow supports it. I read more about it and it looks like the following is not possible in ocaml: |
@bobzhang I think I finished with the types that are representable in flow. Can you review when you have time? If you need any explanation ping me in gitter/discord. There are some types that are not supposed to be worked with in js (like records, lists, etc). They are |
@pvolok it seems that |
I think it's possible to make it as a separate tool. But some things are (in my opinion) in favor of the build-in flow support:
On the other hand, it will add a burden of maintaining additional code. What do you think? |
About the integration, I think it depends on how well the build tool(rebel or whatever tool) works out, my concern is that if there is a hard dependency on buckle(like it needs some information from the buckle compiler) then we should include it, if there is no real dependency then maybe it is better to develop it as a separate tool (and you can also move as fast as you want) |
@bobzhang I was talking about how ocaml types are compiled to js types. While generating flow declarations we use the knowledge of how bs converts types from ocaml to js. For example:
So this flow types generator only makes sense with bs. Sorry if I'm still being cryptic. I will continue to work on this as a separate tool. If you change your mind, we can always merge it. |
@pvolok I understand your comments now. we can revisit this issue later |
Hey @bobzhang I've been working on making flow types generator as a separate tool and encountered a couple of problems:
Maybe you have ideas of how to solve these problems (especially first) or want to reevaluate your decision of keeping flow generator out of the bs src? |
@pvolok |
We have two options how to annotate: inline annotations vs .js.flow files. IMO the latter is the way to go. Its easier to implement and also more performant on the flow side.
Right now I'm working with a
Types.signature
inLam_compile_group.lambda_as_module
. Signature seems to have most of information needed except for function argument names.Things to be implemented:
Related: #671