I'm trying to understand ReasonML's FFI (i.e. external
) usage. To that end, I put together the following code (see Try ReasonML and Sketch.sh)
type dom;
type element;
[@bs.val]
external dom: dom = "document";
[@bs.send.pipe : dom]
external get_by_id: string => element = "getElementById";
let tag = document |> get_by_id("main");
However, the code currently fails with the errors:
Try ReasonML Error
We've found a bug for you! OCaml preview 6:11-18
The value document can't be found
Sketch.sh Error
Error: External identifiers must be functions
Would appreciate help in answering the following questions:
- What are the issues with the code above?
- I believe there are multiple ways to configure the FFI above, e.g. using
[@bs.scope]
- what implications, if any, are there from those ways? -- See follow-up question.