-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix code snippet compile errors #211
base: master
Are you sure you want to change the base?
Conversation
Also fix check-reason for the partial type signatures in this file
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 nice. Thanks so much!
let to_re str = | ||
let is_type_signature, str = | ||
(* assume that any snippet starting with "val" is a partial type signature *) |
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.
Nice.
Error: This expression has type int -> int -> int | ||
but an expression was expected of type ('a -> 'b -> 'c [@u]) |
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.
Is this expected?
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.
Yes, it's expected. This example is supposed to not compile because map
expects an uncurried function as its third argument, but add
is curried.
It's sometimes hard to figure out which snippet is the one that's supposed to break because they aren't extracted in the order that they appear in the markdown file.
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.
I added comments in the prelude of snippets that aren't expected to compile in f79420b
```ocaml | ||
val actionToJs : action -> int | ||
|
||
val actionFromJs : int -> action option | ||
``` | ||
```reasonml | ||
external actionToJs: action => int = ; |
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.
Refmt translates val actionToJs : action -> int
to external actionToJs: action => int = ;
. Is it a bug?
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.
idk but certainly seems syntactically broken cc @davesnx @anmonteiro
@@ -335,12 +349,12 @@ example, the OCaml signature would look like this after preprocessing: | |||
```ocaml | |||
type person | |||
|
|||
val person : name:string -> ?age:int -> unit -> person | |||
external person : name:string -> ?age:int -> unit -> person = "person" |
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.
The ppx actually doesn't put "person" at the end, but I did so to silence the warning from the compiler
@@ -217,9 +231,9 @@ external route : | |||
_type:string -> | |||
path:string -> | |||
action:(string list -> unit) -> | |||
?options:< .. > -> | |||
?options:'a -> |
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.
I tried multiple times to get this snippet to work with Js.t
, but kept getting some variation of this error:
Error The type of this expression, (< .. > as '_weak1) Js.t,
contains the non-generalizable type variable(s): '_weak1.
(see manual section 6.1.2)
See this playground snippet
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.
I rewrote this example based on the feedback I got in our conversation: f13706e
@@ -1014,15 +1045,22 @@ If the values are strings, we can use the `mel.string` attribute: | |||
|
|||
```ocaml | |||
external read_file_sync : | |||
name:string -> ([ `utf8 | `ascii ][@mel.string]) -> string = "readFileSync" | |||
name:string -> ([ `utf8 | `ascii ]) -> string = "readFileSync" |
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.
Keeping the [@mel.string]
generates a warning
File "input.ml", line 4, characters 0-33: | ||
4 | val actionToJs : action -> string | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: Value declarations are only allowed in signatures |
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.
These errors remain because I throw away the beginning (module type _FAKE_ sig
) and end ( end
) when transforming type signatures snippets in process_md.ml
. It's probably fixable, but I'm not sure if it's a big deal.
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.
Didn't fix it but added a comment to indicate that the snippet is a type signature in f79420b
Also fix:
process_md.ml
has been changed so that when it detects a snippet that begins with "val ", it assumes that it contains type signatures and wraps it withmodule type _FAKE_ = sig
andend
. After it converts to reason code, the extra lines are removed.