-
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
Open
feihong
wants to merge
9
commits into
master
Choose a base branch
from
fix-snippet-compile-errors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ea46064
Fix compile errors in build-system.md
feihong 79133f8
Check that reason snippets match ocaml snippets in new markdown files
feihong e57ab51
Fix compile errors in language-concepts.md
feihong 4af47ab
Fix compile errors in data-types-and-runtime-reps.md
feihong c2d67e3
Fix compile errors in advanced-js-interop.md
feihong 190b06b
Fix compile errors in working-with-js-objects-and-values.md
feihong 94858e3
Simplify designature function
feihong f79420b
Add comments to snippets that aren't expected to compile
feihong f13706e
Rewrite the example inside 'using external functions' section
feihong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,15 +126,19 @@ type action = | |
|
||
This will generate a couple of functions with the following types: | ||
|
||
<!--#prelude# | ||
(* type signature *) | ||
type action | ||
--> | ||
```ocaml | ||
val actionToJs : action -> int | ||
|
||
val actionFromJs : int -> action option | ||
``` | ||
```reasonml | ||
external actionToJs: action => int = ; | ||
let actionToJs: action => int; | ||
|
||
external actionFromJs: int => option(action) = ; | ||
let actionFromJs: int => option(action); | ||
``` | ||
|
||
`actionToJs` returns integers from values of `action` type. It will start with 0 | ||
|
@@ -171,15 +175,20 @@ This feature relies on [abstract types](./language-concepts.md#abstract-types) | |
to hide the JavaScript runtime representation. It will generate functions with | ||
the following types: | ||
|
||
<!--#prelude# | ||
(* type signature *) | ||
type action | ||
type abs_action | ||
--> | ||
```ocaml | ||
val actionToJs : action -> abs_action | ||
|
||
val actionFromJs : abs_action -> action | ||
``` | ||
```reasonml | ||
external actionToJs: action => abs_action = ; | ||
let actionToJs: action => abs_action; | ||
|
||
external actionFromJs: abs_action => action = ; | ||
let actionFromJs: abs_action => action; | ||
``` | ||
|
||
In the case of `actionFromJs`, the return value, unlike the previous case, is | ||
|
@@ -208,20 +217,28 @@ type action = | |
``` | ||
```reasonml | ||
[@deriving jsConverter] | ||
type action = [ | `Click | [@mel.as "submit"] `Submit | `Cancel]; | ||
type action = [ | ||
| `Click | ||
| [@mel.as "submit"] `Submit | ||
| `Cancel | ||
]; | ||
``` | ||
|
||
Akin to the variant example, the following two functions will be generated: | ||
|
||
<!--#prelude# | ||
(* type signature *) | ||
type action | ||
--> | ||
```ocaml | ||
val actionToJs : action -> string | ||
|
||
val actionFromJs : string -> action option | ||
``` | ||
```reasonml | ||
external actionToJs: action => string = ; | ||
let actionToJs: action => string; | ||
|
||
external actionFromJs: string => option(action) = ; | ||
let actionFromJs: string => option(action); | ||
``` | ||
|
||
The `jsConverter { newType }` payload can also be used with polymorphic | ||
|
@@ -335,12 +352,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 commentThe 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 |
||
``` | ||
```reasonml | ||
type person; | ||
|
||
external person: (~name: string, ~age: int=?, unit) => person = ; | ||
external person: (~name: string, ~age: int=?, unit) => person = "person"; | ||
``` | ||
|
||
The `person` function can be used to create values of `person`. It is the only | ||
|
@@ -355,7 +372,7 @@ type person = { | |
name : string; | ||
age : int option; [@mel.optional] | ||
} | ||
[@@deriving jsDeriving] | ||
[@@deriving jsProperties] | ||
--> | ||
```ocaml | ||
let alice = person ~name:"Alice" ~age:20 () | ||
|
@@ -529,14 +546,14 @@ type person = { | |
name : string; | ||
mutable age : int; | ||
} | ||
[@@deriving getSet] | ||
[@@deriving jsProperties, getSet] | ||
|
||
let alice = person ~name:"Alice" ~age:20 | ||
|
||
let () = ageSet alice 21 | ||
``` | ||
```reasonml | ||
[@deriving getSet] | ||
[@deriving (jsProperties, getSet)] | ||
type person = { | ||
name: string, | ||
mutable age: int, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
toexternal 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