0

我正在定义一个类如下

    class dataframe (csv_filepath:string) =
        object
               (* Load the csv, make it square and print the first line *)
               initializer  
                    let print_first_line csv_filepath =
                        let f = Csv.square (Csv.load csv_filepath) in
                        let top_line = Csv.sub 0 0 1 (Csv.columns f) f in
                        Csv.print_readable top_line;
                        Printf.printf "\n";
        end;;

并收到错误消息

   end;;
   ^^^
   Error: Syntax error

我看不出有什么问题,我完全迷路了,有人知道发生了什么吗?

4

1 回答 1

1

您必须在初始化程序中编写一个表达式。你在这里写的是一个函数定义顶级短语。正确的初始化程序应如下所示:

initializer
  let print_first_line csv_filepath =
    let f = Csv.square (Csv.load csv_filepath) in
    let top_line = Csv.sub 0 0 1 (Csv.columns f) f in
    Csv.print_readable top_line;
    Printf.printf "\n"
  in
  (* Use print_first_line you defined *)
  print_first_line csv_filepath

或者只是简单地

initializer
  let f = Csv.square (Csv.load csv_filepath) in
  let top_line = Csv.sub 0 0 1 (Csv.columns f) f in
  Csv.print_readable top_line;
  Printf.printf "\n"
于 2013-09-17T01:48:10.157 回答