GithubHelp home page GithubHelp logo

Comments (6)

hhugo avatar hhugo commented on August 30, 2024

Likely a bug in js_of_ocaml. Can you open an issue with details on how to reproduce.

from gen_js_api.

Armael avatar Armael commented on August 30, 2024

Ok. Done here: ocsigen/js_of_ocaml#573

from gen_js_api.

Armael avatar Armael commented on August 30, 2024

As noticed by @hhugo on ocsigen/js_of_ocaml#573 , the ml code generated by gen_js_api from val foo : int -> unit is incorrect. With an explicit [@@js.global] annotation, it is correct.

val foo : int -> unit

produces

let (foo : int -> unit) =
  fun x1  -> ignore (Ojs.call (Ojs.int_to_js x1) "foo" [||])

while

val foo : int -> unit
[@@js.global]

produces

let (foo : int -> unit) =
  fun x1  -> ignore (Ojs.call Ojs.global "foo" [|(Ojs.int_to_js x1)|])

However, if I understand https://github.com/LexiFi/gen_js_api/blob/master/VALUES.md#automatic-binding correctly, the [@@js.global] should not be necessary and not providing it should work just the same, which is not the case currently.

from gen_js_api.

alainfrisch avatar alainfrisch commented on August 30, 2024

The relevant case from VALUS.md is:

If the value is a function with a single argument (named type) t -> unit, then the declaration is assumed to be a [@@js.call] method call, unless a [@js.scope] attribute has been defined in an englobing module. In this latter case, the value is assumed to be a [@@js.global] value.

Do you see something else that would contradict this interpretation?

from gen_js_api.

Armael avatar Armael commented on August 30, 2024

Ah, now I understand the paragraph you are mentionning. I think I may have been confused by "a single argument (named type) t -> unit"; and interpreted it as "the type must literally be named t", while, if I understand correctly, t must be read as a meta-variable here?

Maybe this paragraph could be clarified a bit? Additionally, I don't know why, but when quickly reading through the paragraph, I seem to incorrectly interpret the last sentence as Otherwise, the value is assumed ..., with the Otherwise referring to the first If. Maybe reformulating things could make the whole paragraph a bit clearer.

from gen_js_api.

alainfrisch avatar alainfrisch commented on August 30, 2024

I've changed this section to use greek letters for meta-variables. If you have some ideas to improve the text, don't hesitate to create a PR!

from gen_js_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.