How do I resolve type mismatch arising due to a Functor?

Here is a simplified example of a Functor setup in my codebase. The module Number which is a module of type Item, is passed as an argument to functor Make. The resulting types SpecificItem.t and Number.t are (to my eyes, but not to the compiler) the same. Hence the compiler calls out the type mismatch on this line:

let integers = values->Array.map(Number.toInt)

This (values) has type: array<SpecificItem.t>
  Somewhere wanted: 'a => 'b

But how do I reconcile the types array<SpecificItem.t> with array<Number.t> for this line of code?

You are using Array.map (which is data last), combined with first pipe (->).

If you use Belt.Array.map instead, everything compiles:

https://rescript-lang.org/try?version=v10.1.2&code=LYewJgrgNgpgBAFwJ4Ad4EkE2HAvHAbwCg5FV4ES5YE5gBDBAYwAsAuOACgQBpEBKPAD44AIxAgoRAL5EioSLDgBZegGt4+TpmwcdwQbhHFSyNIjxx9AOkpUaceijQA7MJc70O9AE4-6SAA8CEJ8AJZYwBwIhiL0ALRCAEIwUAjWAIJ+AdZMIC5MjJwA2hHYALr8MnIK0PAAchDAojA+liZk5rT46C5YAOatnGF9ggA+cABiUCBFAGYzjFWkDgzMLB4AbgCMfJsATLFwO3j4B-YwtAggvd3HwlSkAM4A7hGs9x2kE7cwgz7DI5hR5wCbTWYIThzI5zRIpNLWcGMWw3Pog2SyeTgOpwADKaCYYTmYSY+ksqg0nEazVaVSIDk29CgEBgT282SC+JghOJpMithEuCoxXKiS5PJJNicrjA2j6fyG234-DFBKJkv50pgbk4SMhAGZrNsACzK+mXOAjAatJ6WRnM1lw1LpLL+JDWBgoKlNFo+FG3KpAA

1 Like

Thank you! I misunderstood the compiler message.

My codebase uses JS/Belt/ReScriptCore and it’s transitioning to RescriptCore. I should have figured that out :sweat_smile: .

I suggest taking a look at GitHub - DZakh/rescript-stdlib-vendorer: Tool to support usage of a vendored standard library in ReScript. It’ll help with transition and prevent the Js/Belt usage in the future.

1 Like