Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在F#编程语言中是否有类似于Python函数装饰器的东西?_Python_F#_Decorator - Fatal编程技术网

在F#编程语言中是否有类似于Python函数装饰器的东西?

在F#编程语言中是否有类似于Python函数装饰器的东西?,python,f#,decorator,Python,F#,Decorator,我正在学习F#,并且有一些Python方面的经验。我真的很喜欢Python函数装饰器;我只是想知道在F#中是否有类似的东西 F#中的函数装饰器没有语法上的糖分 对于类型,可以使用StructuredFormatDisplay属性自定义printf内容。以下是一个例子: [] 类型C(元素:整数列表)= 成员x.内容=元素 让printfnSample() printfn“%A”(C[1..4]) //MyType是[1;2;3;4] 对于函数,可以使用函数组合轻松表示。比如说, def ma

我正在学习F#,并且有一些Python方面的经验。我真的很喜欢Python函数装饰器;我只是想知道在F#中是否有类似的东西

F#中的函数装饰器没有语法上的糖分

对于类型,可以使用
StructuredFormatDisplay
属性自定义printf内容。以下是一个例子:

[]
类型C(元素:整数列表)=
成员x.内容=元素
让printfnSample()
printfn“%A”(C[1..4])
//MyType是[1;2;3;4]
对于函数,可以使用函数组合轻松表示。比如说,

def makebold(fn):
def wrapped():
返回“+fn()+”
退货包装
def MAKE斜体(fn):
def wrapped():
返回“+fn()+”
退货包装
@马克博尔德
@使斜体
def hello():
返回“你好,世界”
可以翻译为F#,如下所示

让makebold fn=
乐趣()->“+fn()+”
让我们来看看=
乐趣()->“+fn()+”
让我打个招呼=
让hello=fun()->“hello world”
(另请参见。
[<StructuredFormatDisplayAttribute("MyType is {Contents}")>]
type C(elems: int list) =
   member x.Contents = elems

let printfnSample() = 
    printfn "%A" (C [1..4])

// MyType is [1; 2; 3; 4]