ocaml函数结果作为另一个函数中的参数

Fre*_*ikA 1 ocaml function

我有一个与OCaml有关的问题。我的问题是:如何将函数结果作为参数传递给另一个函数?例:

let function a b = a/b;;

let anotherFunction p t = p + t;;

function 10 5;;
Run Code Online (Sandbox Code Playgroud)

我可以通过从结果功能(2)一个参数-比方说牛逼anotherFunction ¨?

谢谢!

Jef*_*eld 5

您不能有一个名为的函数function,这是OCaml中的关键字。所以我们称之为firstFunction

我认为您要的是这样的:

 anotherFunction 13 (firstFunction 10 5)
Run Code Online (Sandbox Code Playgroud)

这是一个顶级会话:

# let firstFunction a b = a / b;;
val firstFunction : int -> int -> int = <fun>
# let anotherFunction p t = p + t;;
val anotherFunction : int -> int -> int = <fun>
# anotherFunction 13 (firstFunction 10 5);;
- : int = 15
Run Code Online (Sandbox Code Playgroud)

(对于像这样的简单问题,可能需要花一些时间在顶层输入表达式。它应该很快就会变得有意义。)