【发布时间】:2013-06-17 23:23:23
【问题描述】:
我在方法类中遇到了可选参数的问题。
让我解释一下。我有一个寻路类graph(在Wally 模块中)和一个他的方法shorthestPath。它使用可选参数。事实是,当我调用(使用或不使用可选参数)此方法 OCaml 返回类型冲突时:
Error: This expression has type Wally.graph
but an expression was expected of type
< getCoor : string -> int * int;
getNearestNode : int * int -> string;
shorthestPath : src:string -> string -> string list; .. >
Types for method shorthestPath are incompatible
而shorthestPath 类型是:
method shorthestPath : ?src:string -> string -> string list
我同样尝试将选项格式用于可选参数:
method shorthestPath ?src dst =
let source = match src with
| None -> currentNode
| Some node -> node
in
...
只有在我删除可选参数的情况下,OCaml 才会停止侮辱我。
提前感谢您的帮助:)
【问题讨论】:
-
你是怎么调用这个方法的?
-
哈,是的。例如:
let path = self#getNodes#shorthestPath ~src:"begin" node in ...。self#getNodes方法获取Graph实例。
标签: class methods ocaml optional-arguments