reasonml.github.io
reasonml.github.io copied to clipboard
List vs Array advice for beginners
Hello,
I've been reading the documentation specially the interop section as I'm just starting to play with Reason and I have to interact with Javascript a lot.
I ended up running node
to test my explorations and I got trapped into a non-obvious situation. This is the problem I faced:
I had a function in Reason such as:
let length = (xs: list(string)): int => List.length(xs)
And I used like that in node:
> require('./lib/js/src/Test.bs.js').length([])
1
I didn't expect this at all, so I tried:
> require('./lib/js/src/Test.bs.js').length(["foo"])
1
At this point I was totally lost. I spent some (too much) time re-reading the docs and I couldn't figure out the problem. After that, I asked on Discord and the answer was "don't use functions that expect lists from javascript, use arrays". Fair enough.
I guess that this issue is to suggest to add advice on that or more generally how to guard yourself from javascript-land when you are writing code in Reason and toying with it in node.