小编Abd*_*lah的帖子

以下函数是否存在标准名称?

似乎我一遍又一遍地使用我希望作为函数抽象的模式.模式背后的想法是,我可能有一些东西,如果没有,我可以尝试生产它.这是我对命名感兴趣的函数的一些OCaml代码,但问题不是OCaml特定的.我找了一个Haskell先例,但我没有在Data.Maybe模块中看到这样的函数,并且hoogle也没有帮助:http://www.haskell.org/hoogle/? human = Maybe + b + - %3E +%28a + - %3E +可能+ b%29 + - %3E + a + - %3E +可能+ b.

let my_function a f arg = match a with
  | None -> f arg
  | Some _ -> a
Run Code Online (Sandbox Code Playgroud)

这几乎就像有一个默认的潜在价值,但如果我们已经有一个值,它就不需要生成默认值.

编辑:

我需要这种类型的原因是我有一个要解决的组合问题和一组解决它的启发式(比如h1和h2).h1比h2快.但是,这些启发式方法都不能保证找到解决方案.所以我将它们链接起来并按顺序尝试.就像是

match my_function (h1 problem) h2 problem with
| None -> "bad luck"
| Some solution -> "hurray"
Run Code Online (Sandbox Code Playgroud)

ocaml haskell naming-conventions

4
推荐指数
1
解决办法
238
查看次数

如何在OCaml中的各个模块之间使用GADT,而不会发出警告?

我有两个文件:gadt1.ml和gadt2.ml,第二个取决于第一个。

gadt1.ml:

type never
type _ t1 = A1 : never  t1 | B1 : bool t1
type _ t2 = A2 : string t2 | B2 : bool t2
let get1 : bool t1 -> bool = function B1 -> true
let get2 : bool t2 -> bool = function B2 -> true
Run Code Online (Sandbox Code Playgroud)

gadt2.ml:

let get1 : bool Gadt1.t1 -> bool = function Gadt.B1 -> true
let get2 : bool Gadt1.t2 -> bool = function Gadt.B2 -> true
Run Code Online (Sandbox Code Playgroud)

当我使用ocaml …

ocaml types pattern-matching compiler-warnings gadt

4
推荐指数
1
解决办法
150
查看次数

为什么一些标准的ocaml库是opam包而有些不是?

base-unix在OCaml opam存储库中看到了这个包.它被描述为"与OCaml编译器一起分发的Unix库".与OCaml编译器一起分发的一些其他库没有自己的包.例如,没有库的base-strstr.

为什么会有这样的差异?据我所知,在使用ocamlfind或编译时,它们都需要在命令行中指定为包或库ocamlbuild.

ocaml ocamlfind opam

2
推荐指数
1
解决办法
158
查看次数