syntax-error - ocaml 出现语法错误
问题描述
当我尝试在 oCaml 中运行此代码时,我在“module usingTable : TABLE =" 行出现语法错误,并且 usingTable 一词以红色突出显示。我想创建格式的表,如下面的执行示例所示。它有什么问题?我使用的环境是这个https://try.ocamlpro.com/fun-demo/tryocaml_index.html#path%3Dtries因为我不明白如何在 Windows 中使用 cygwin 或 oCaml Bash。
module type TABLE =
sig
type table
val emptyTable : table
val printTable : table -> string
val create_table : string * string list * (string list) list -> table
end;;
module usingTable : TABLE =
struct
let emptyTable = ()
let table = (string * (string * string list) list)
let rec printTable aTable = match aTable with
()->""
| (title, [data]) -> "\n"^title^"\n\n"^printTable(data)
| [(col,cont)::t] -> col^" "^printTable([t])
end;;
let atable = usingTable.emptyTable;;
let atable = ("Student", [("Id", ["2";"4";"7";"9"]);
("Name", ["Jim";"Linnea";"Steve";"Hannah"]);
("Gender",["Male";"Female";"Male";"Female"]);
("Course",["Geography";"Economics";"Informatics";"Geography"])
]);;
print_string (usingTable.printTable atable) ;;
解决方案
正如我在评论中所建议的那样,在再次关注此代码示例(不仅包含语法错误,还包含类型错误)之前,您可能需要查看一些其他参考资料。
例如,我建议以下链接:
- 官方 OCaml 教程,特别是你可能首先看一下 :
- OCaml中所谓的99题(相当标准的练习集);
- Real World OCaml (一本全面了解 OCaml 的在线书籍);
- 官方OCaml 参考手册;
- 并且手动获取 Stdlib 模块(即,始终默认加载的标准库的模块)的 doc 的 URL 也可能很有用;
- 最后,如果您正在寻找“标准风格建议/最佳实践”的汇编,OCaml 编程指南页面可能会有所帮助。
推荐阅读
- html - 如何将弹出窗口放在叠加层上
- php - woocommerce 订阅在另一个地方添加续订按钮
- mongodb - 仅当不存在类似文档时才向 Mongo 插入新文档
- python - Json键值与文本文件属性匹配 - Python
- gitlab - 将域添加到管理区域中的出站请求时出现 Gitlab Omnibus 500 错误
- python - 使用正则表达式识别包含整个“名称”的文本行(更新问题)
- javascript - 如何在不直接使用属性名称访问的情况下访问 javascript 对象属性
- python - 登录python时包含stderr和stdout
- reactjs - 使用 testing-library 测试 cleave.js 组件
- python - 作为客户端,如何避免python中TCP/IP套接字中的CLOSE_WAIT?