Reason 是否支持可空类型?

Does Reason support nullable types?

这是一个新手问题,但我在任何地方都找不到快速答案。

Facebook 的 Reason 语言是否支持可空类型?如果是,是什么形式?

没有null。我们拥有的最接近的是选项变体。请参阅以下各种文档:

https://reasonml.github.io/docs/en/newcomer-examples.html#using-the-option-type https://reasonml.github.io/docs/en/variant.html#option

让我知道您是否在 JavaScript 中有 null 的特定情况,您希望看到 Reason 等效项。

正如 Neil 所说,Reason 本身有 the option type. However, if you have to deal with possible null or undefined values from JavaScript, there's also Js.Nullable.t. It can be converted to an option when needed using Js.toOption.

还有更具体的类型,它们只能处理 nullundefined,而另一个,分别处理 Js.Null.t and Js.Undefined.t,但您很少需要这些类型。我提到它们只是为了完整起见。