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

Handling null/undefined in JS interop #191

@rtfeldman

Description

@rtfeldman

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions