Skip to content

Instantly share code, notes, and snippets.

@tuchk4

tuchk4/test.re Secret

Last active June 8, 2017 07:25
Show Gist options
  • Save tuchk4/7130405338a41a7a91b6de22356c072e to your computer and use it in GitHub Desktop.
Save tuchk4/7130405338a41a7a91b6de22356c072e to your computer and use it in GitHub Desktop.
type point = {x: int, y: int};
let coords: list point = [];
let printCoords () => List.iter (fun c => Js.log c) coords;
let append raw =>
Array.iter
(
fun data => {
let p = {x: process data.x, y: process data.y};
/* append p to coords */
()
}
)
raw;
append data1;
append data2;
append data3;
printCoords ();
@yawaramin
Copy link

yawaramin commented Jun 7, 2017

Oh, you can handle scope by passing a required variable in as a function argument, thus ensuring it's in scope. E.g.:

let printCoords coords => List.iter Js.log coords;

let coords = List.map (fun {x, y} => {x: process x, y: process y}) [data1, data2, data3];

let () = printCoords coords;

@tuchk4
Copy link
Author

tuchk4 commented Jun 8, 2017

I know this.
I didn't asked how to rewrite this code to make it work.
I am interesting how to be with immutable vars that I need to change(

append data1;
append data2;
append data3;

printCoords ();

append data4;
append data5;

printCoords ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment