[英]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”位不是表达;我认为它可以出现在三个不同的上下文中:
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.