我正在學習ocaml,所以它可能是微不足道的。「Real World Ocaml」中的示例代碼未按預期運行。
當我嘗試建立這個代碼的可執行文件:
open Core.Std
let build_counts() =
In_channel.fold_lines stdin ~init:[] ~f:(fun counts line ->
let count =
match List.Assoc.find counts line with
| None -> 0
| Some x -> x
in
List.Assoc.add counts line (count + 1)
)
let() =
build_counts()
|> List.sort ~cmp:(fun (_,x) (_,y) -> Int.descending x y)
|> (fun l -> List.take l 10)
|> List.iter ~f:(fun (line,count) -> printf "%3d: %s\n" count line)
我得到這個錯誤:
Error: This pattern matches values of type 'a option but a pattern was expected which matches values of type equal:(Stdio__.Import.string -> Stdio__.Import.string -> bool) -> 'b option
問題出在哪裏?
鏈接:https://realworldocaml.org/v1/en/html/files-modules-and-programs.html
奇怪的是,它對我沒有任何影響 –
可能取決於你的'core'版本。 :) – RichouHunter