The canonical example of JS interop is console.log, which returns nothing. We have a test showing that we can coerce console to Number if need be.
But what about handling return values from calls to JS functions? Since Roy doesn't have null or undefined, how do we handle the case where we get one of those values back?
One approach would be to include something along the lines of JSOption in the core (or stdlib?), and wrap all JS return values in it:
data JSOption value = Some value | Null | Undefined
match strFromJsFunction
case (Some (Str str)) = console.log str
case Null = console.log "Got back null"
case Undefined = console.log "Got back undefined"
On the flip side, there's also the question of how to interact with JS APIs that require passing null or undefined under certain circumstances. One approach would be to give JSOption special treatment when making calls out, having Null compile to just the JS literal null, Some foo compile out to just foo, etc. I'm not a fan of special treatment in general, but it's at least a starting point for discussion.
The canonical example of JS interop is
console.log
, which returns nothing. We have a test showing that we can coerceconsole
toNumber
if need be.But what about handling return values from calls to JS functions? Since Roy doesn't have
null
orundefined
, how do we handle the case where we get one of those values back?One approach would be to include something along the lines of
JSOption
in the core (or stdlib?), and wrap all JS return values in it:On the flip side, there's also the question of how to interact with JS APIs that require passing
null
orundefined
under certain circumstances. One approach would be to giveJSOption
special treatment when making calls out, havingNull
compile to just the JS literalnull
,Some foo
compile out to justfoo
, etc. I'm not a fan of special treatment in general, but it's at least a starting point for discussion.Thoughts?