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) 我正在使用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) 创建 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) 我试图使用Int32库编写一些代码,但我遇到了类型错误:
let x : int = 7;
Int32.abs(x)
This has type:
int
But somewhere wanted:
int32
Run Code Online (Sandbox Code Playgroud)
我对此感到有些惊讶,因为在其他语言int中只是一个别名int32.
我的问题是:
Int32.abs但是没有Int.abs,例如)