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

Confusing type error when transforming from OCaml's stdlib Array to RescriptCore.Array #6263

Closed
ryyppy opened this issue May 23, 2023 · 3 comments · Fixed by #6264
Closed

Comments

@ryyppy
Copy link
Member

ryyppy commented May 23, 2023

Minimal example:

open RescriptCore

let arr = [1,2,3]

Array.map((a) => a + 1, arr)

Yields the following type error:

[E] Line 5, column 10:
This has type: \"function$"<'a, [#Has_arity1]>
  Somewhere wanted: array<'b>

Playground Link

The playground comes with uncurried set to true.

I assume \"function$"<'a, [#Has_arity1]> is the internal name for an uncurried callback function?

@cristianoc
Copy link
Collaborator

cristianoc commented May 24, 2023

Self contained:

let foo = (x: array<_>) => ()
let x = foo(a => a + 1)

@cristianoc
Copy link
Collaborator

This is the parse tree (in ml syntax for readability):

let foo = ((Function$ (fun (x : _ array) -> ()))[@res.arity 1])
let x = ((foo ((Function$ (fun a -> a + 1))[@res.arity 1]))[@res.uapp ])

@cristianoc
Copy link
Collaborator

What's going on is that the Function$ processing produces type $function<funtype, arity> but since the type error happens before unification, funtype is still 'a.
So all is known to the type system is that this is a function.

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

Successfully merging a pull request may close this issue.

2 participants