标签: reasonml

如何在Reason ML中声明地图类型?

Reason ML优于JavaScript的一个优点是它提供了Map一种使用结构相等而不是引用相等的类型.

但是,我找不到这个用法的例子.

例如,我如何声明一个scores字符串映射到整数的类型?

/* Something like this */
type scores = Map<string, int>; 
Run Code Online (Sandbox Code Playgroud)

我将如何构建一个实例?

/* Something like this */
let myMap = scores();

let myMap2 = myMap.set('x', 100);
Run Code Online (Sandbox Code Playgroud)

ocaml dictionary reason reasonml

12
推荐指数
2
解决办法
2336
查看次数

graphql reason-apollo - 递归解析选项

我正在使用Reason-Apollo从我的服务器解析一个非常嵌套的GraphQL响应.我无法解析从GraphQL服务器返回的毛茸茸树的选项(我正在使用django-graphene).

这是使用Reason Apollo的GraphQL查询和Reason React模块:

module GroupQuery = [%graphql {|
query GetChatGroup($chatGroupId: ID!){
  chatGroup(id: $chatGroupId) {
    id
    users {
      edges {
        node {
          id
          name
          isCurrentUser
        }
      }
    }
    messages {
      edges {
        node {
          id
          text
          author {
            name
            abbreviation
            photoUrl
            isCurrentUser
          }
        }
      }
    }
  }
}
|}];

/*eventually will be a reducerComponent*/
let component = ReasonReact.statelessComponent("RechatWindow");

module Query = RechatApollo.Instance.Query;

let parseMessages = chatGroup =>
  switch chatGroup {
  | Some(chatGroup) =>
    switch chatGroup##messages {
    | Some(messages) …
Run Code Online (Sandbox Code Playgroud)

django graphql reason graphene-python reasonml

5
推荐指数
1
解决办法
301
查看次数

编译 reducerComponent 时出错“这是 ReasonReact reducerComponent 还是带有保留道具的组件?”

创建 reducerComponent 时出现错误:

代码

type state = {repoData: RepoData.repo};

let dummyRepo: RepoData.repo = {
  stargazers_count: 27,
  full_name: "jsdf/reason-react-hacker-news",
  html_url: "https://github.com/jsdf/reason-react-hacker-news"
};

let component = ReasonReact.reducerComponent("Page1");

let make = (_children) => {
  ...component,
  initialState: () => {
    repoData: dummyRepo
  },
  render: (self) => {
    <div className="App">
      <h1>{ReasonReact.stringToElement("Reason Projects")}</h1>
      <RepoItem repo={self.state.repoData} />
    </div>
  }
};
Run Code Online (Sandbox Code Playgroud)

错误:

Failed to compile.

./src/index.re
Module build failed: Error: We've found a bug for you!
  /Users/me/personal/test/reason-app-shell-starter-kit/src/page1.re 9:17-53

   7 ? };
   8 ?
   9 ? let component = …
Run Code Online (Sandbox Code Playgroud)

reason reason-react reasonml

5
推荐指数
1
解决办法
294
查看次数

Reason ML中的整数类型和模块是什么?

我试图使用Int32库编写一些代码,但我遇到了类型错误:

let x : int = 7;
Int32.abs(x)

This has type:
  int
But somewhere wanted:
  int32
Run Code Online (Sandbox Code Playgroud)

我对此感到有些惊讶,因为在其他语言int中只是一个别名int32.

我的问题是:

  • Reason ML中可用的整数类型是什么?
  • 使用它们的准则是什么?
  • 每个都有一个模块吗?(我注意到Int32.abs但是没有Int.abs,例如)

ocaml integer reason reasonml

2
推荐指数
1
解决办法
329
查看次数