F# 语句的语义

发布于 2024-07-20 06:04:37 字数 282 浏览 4 评论 0原文

有人可以向我描述这个 F# 表达式吗?

val augment: GameGrid -> points -> unit

val 关键字是什么意思?

通常 type -> 是真的吗? type表示返回指定类型的函数? type -> 也是如此 类型-> type表示一个函数,该函数返回一个返回指定类型的函数?

Can someone describe this F# expression to me?

val augment: GameGrid -> points -> unit

What does the val keyword mean?

Is it true that usually type -> type indicates a function that returns the specified type? So does type -> type -> type indicate a function that returns a function that returns the specified type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热情消退 2024-07-27 06:04:37

(“val”位不是一个表达式;我认为它可以出现在三种不同的上下文中:

  • FSI(F# 交互式 REPL)的输出、描述
  • 签名 (.fsi) 文件中绑定的推断类型、描述 let 绑定模块值的类型
  • 结构/类定义中

(“显式”语法),用于定义实例变量,并且这些都不是技术上的表达式上下文。)

至于类型,确实

A1 -> A2 -> R

意味着采用 A1 的函数,并返回一个接受 A2 并返回 R 的函数。参数是柯里化的,阅读例如

F# 函数类型:元组和柯里化的乐趣

更详细地描述了柯里化和部分应用程序。

(The 'val' bit is not an expression; offhand I think it can appear in three different contexts:

  • the output of FSI (F# interactive REPL), describing the inferred type of a binding
  • in a signature (.fsi) file, describing the type of a let-bound module value
  • in a struct/class definition ('explicit' syntax), to define an instance variable

and none of those are technically expression contexts.)

As for the type, indeed

A1 -> A2 -> R

means a function that takes an A1, and returns a function that takes an A2 and returns an R. The arguments are curried, and it may do you well to read e.g.

F# function types: fun with tuples and currying

which describes currying and partial application in more detail.

相权↑美人 2024-07-27 06:04:37

你是如何得到这个输出的? 在金融服务机构?

Val只是表示一个值的定义。

例如,如果您在 C# 中编写了以下内容,

private void Foo(int i);

您将在 F# 中编写此内容

val Foo : int -> unit

关于 type -> 类型-> type:这是一个带有两个参数(类型)的函数,返回“type”

,例如

let plus a b = a + b

具有签名 int -> 整数-> int

您关于返回函数的函数的想法实际上是正确的。 在许多函数式语言中,这是一种非常有趣的技术,称为柯里化(currying)。

How did you get this output? In FSI?

Val just indiciates a definition of a value.

E.g. if you wrote the following in C#

private void Foo(int i);

you would write this in F#

val Foo : int -> unit

Concerning type -> type -> type: This is a function with two parameters (type) returning `type´

E.g.

let plus a b = a + b

has got signature int -> int -> int.

Your idea with a function that returns a function is actually correct. This is a very interesting technique in many functional languages called currying

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文