Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Handling null/undefined in JS interop #191

Open
rtfeldman opened this issue Aug 1, 2013 · 0 comments
Open

Handling null/undefined in JS interop #191

rtfeldman opened this issue Aug 1, 2013 · 0 comments

Comments

@rtfeldman
Copy link
Collaborator

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.

Thoughts?

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

No branches or pull requests

1 participant