Skip to content
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

Strange behavior when using unit in externals #1022

Open
jchavarri opened this issue Jan 9, 2024 · 3 comments
Open

Strange behavior when using unit in externals #1022

jchavarri opened this issue Jan 9, 2024 · 3 comments

Comments

@jchavarri
Copy link
Member

The following code:

external useFoo : unit -> string -> string = "useFoo"

let foo = useFoo ()
let t = foo ""

generates this output:

function foo(param) {
  return useFoo(param);
}

var t = useFoo("");

Playground.

Note how t is converted into useFoo("") and not useFoo(undefined, ""). When using any other type, the first parameter will be passed just fine:

external useFoo : int -> string -> string = "useFoo"

let foo = useFoo 2
let t = foo ""

Output:

function foo(param) {
  return useFoo(2, param);
}

var t = useFoo(2, "");

Playground

Is this expected?

@anmonteiro
Copy link
Member

anmonteiro commented Jun 16, 2024

I'm looking into this, but one workaround is:

type t = unit

external useFoo : t -> string -> string = "useFoo"

@anmonteiro
Copy link
Member

I still need to do more digging, but the issue here seems to be that unit is ignored for cases like:

type t

external foo: unit -> t = ""

and generating foo() instead of foo(undefined)

@anmonteiro
Copy link
Member

One idea is to only elide the unit argument when it appears before the return value, but a "return value" could be a function, too.

This might work well with uncurried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants