Ocaml 如何将JavaScript值转换为reasonml中的变量?

Ocaml 如何将JavaScript值转换为reasonml中的变量?,ocaml,reason,bucklescript,Ocaml,Reason,Bucklescript,JavaScript中有三个值: 结果。已授予 结果。拒绝 Result.neverAskAgain 如何将它们转换为变体 type result = | Granted | Denied | NeverAskAgain; 编辑:更好的选择是使用 您可以绑定到这些值,然后编写一个函数,将这些值转换为变量 绑定到以下值: type t'; [@bs.module "result"] external granted: t'; [@bs.module "result"

JavaScript中有三个值:

  • 结果。已授予
  • 结果。拒绝
  • Result.neverAskAgain
如何将它们转换为变体

type result =
    | Granted
    | Denied
    | NeverAskAgain;

编辑:更好的选择是使用

您可以绑定到这些值,然后编写一个函数,将这些值转换为变量

绑定到以下值:

type t';

[@bs.module "result"] external granted: t';
[@bs.module "result"] external denied: t';
[@bs.module "result"] external neverAskAgain: t';
然后将其转换为变体:

type t = Granted | Denied | NeverAskAgain;

let fromJS = t' =>
  switch (t' === granted, t' === denied, t' === neverAskAgain) {
  | (true, _, _) => Granted
  | (_, true, _) => Denied
  | (_, _, true) => NeverAskAgain
  };

这些值是否来自模块?还是上课?还是别的什么?@Yawar这些是来自js库的。