首页 > 解决方案 > 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) ;;

标签: syntax-errorocaml

解决方案


正如我在评论中所建议的那样,在再次关注此代码示例(不仅包含语法错误,还包含类型错误)之前,您可能需要查看一些其他参考资料。

例如,我建议以下链接:


推荐阅读