Search code examples
syntax-errorocaml

ocaml getting syntax error


I am getting syntax error on the line "module usingTable : TABLE =" and the word usingTable is highlighted red when I try to run this code in oCaml. I want to create table of the format as in the execution example bellow. What is wrong with it? The environment I am using is this one https://try.ocamlpro.com/fun-demo/tryocaml_index.html#path%3Dtries as I couldn't understand how to use cygwin or oCaml Bash in windows.

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) ;;

Solution

  • As suggested in my comment, you may want to take a look at some additional references before focusing again on this code example (which contained not only syntax errors but also type errors).

    For example, I'd suggest the following links: