ghcjs/ghcjs-base — pull request #9 by mtolly (2014-10-12 23:15:13+00:00)
Title: FromJSRef instance for Maybe a

This adds a `FromJSRef` instance for `Maybe a`, which deserializes `null`/`undefined` into `Nothing`, and otherwise tries to deserialize `x` into `Just x`. This mirrors the corresponding `ToJSRef` instance which serializes `Just x` into JS `x`, and `Nothing` into `null`. As a result, it will only fail (return `Nothing`) if the value is non-`null`, non-`undefined`, and also can't be read as an `a`.

I think adding `undefined` as a valid representation of `Nothing` is useful, first because the semantics of `null` and `undefined` in JS code somewhat overlap, and also so that `Maybe a` can represent e.g. a value in an object that may or may not have the value's key.