简体   繁体   English

F#语句的语义

[英]Semantics of F# statement

Can someone describe this F# expression to me? 有人可以向我描述这个F#表达式吗?

val augment: GameGrid -> points -> unit

What does the val keyword mean? val关键字是什么意思?

Is it true that usually type -> type indicates a function that returns the specified type? 通常type -> type指示返回指定类型的函数是否正确? So does type -> type -> type indicate a function that returns a function that returns the specified type? 那么type- type -> type -> type表示返回一个返回指定类型的函数的函数?

(The 'val' bit is not an expression; offhand I think it can appear in three different contexts: (“ val”位不是表达;我认为它可以出现在三个不同的上下文中:

  • the output of FSI (F# interactive REPL), describing the inferred type of a binding FSI(F#交互式REPL)的输出,描述了绑定的推断类型
  • in a signature (.fsi) file, describing the type of a let-bound module value 在签名(.fsi)文件中,描述了让约束模块值的类型
  • 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 eg 表示接受A1的函数,并返回接受A2并返回R的函数。这些参数是经过咖喱处理的,它可能会很好地读取例如

F# function types: fun with tuples and currying F#函数类型:元组和Curying的乐趣

which describes currying and partial application in more detail. 其中更详细地描述了currying和部分应用程序。

How did you get this output? 您如何获得此输出的? In FSI? 在FSI中?

Val just indiciates a definition of a value. Val仅代表一个值的定义。

Eg if you wrote the following in C# 例如,如果您在C#中编写了以下内容

private void Foo(int i);

you would write this in F# 你可以用F#来写

val Foo : int -> unit

Concerning type -> type -> type : This is a function with two parameters (type) returning `type´ 关于type-> type- type -> type -> type :这是一个带有两个参数(类型)的函数,返回“ type”

Eg 例如

let plus a b = a + b

has got signature int -> int -> int . 拥有签名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 在许多称为currying的功能语言中,这是一种非常有趣的技术

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM