[<ReflectedDefinition>]
let rec x = (fun() -> x + "abc")()
与上面的递归值会产生以下F#编译器错误示例代码:这是一个F#语录错误吗?
error FS0432: [<ReflectedDefinition>] terms cannot contain uses of the prefix splice operator '%'
我看不到上面的代码中的任何切片运算符的使用,看起来像一个bug ...... :)
看起来这是通过ReflectedDefinitionAttribute
报价的问题只,正常报价行之有效:
let quotation =
<@ let rec x = (fun() -> x + "abc")() in x @>
产生预期结果与隐藏Lazy.create
和Lazy.force
用法:
val quotation : Quotations.Expr<string> =
LetRecursive
([(x, Lambda (unitVar,
Application
(Lambda (unitVar0,
Call (None,
String op_Addition[String,String,String](String, String),
[Call (None,
String Force[String](Lazy`1[System.String]), // `
[x]), Value ("abc")])),
Value (<null>)))),
(x, Call (None, Lazy`1[String] Create[String](FSharpFunc`2[Unit,String]), [x])),
(x, Call (None, String Force[String](Lazy`1[String]), [x]))], x) // `
所以,问题是:这是一个F#编译器错误或不?
谢谢你的回答,托马斯! 我不同意你,当我写''[]'版本元数据应该看起来像'<@ (fun() ->%x +“abc”)()@>'。在内部引用中,'x'名称应该绑定到公共.NET值,而不是引用片段!如果它的行为像你说的那样,代码就像这样:'[]让rec f()=(fun() - > f()+“abc”)()'也会产生相同的效果,但事实并非如此。 –
ControlFlow
2010-05-30 16:06:39
@ControlFlow:我认为你的观点是有道理的。也许这必须通过递归值来实现,这在F#中通常是非常复杂的事情。 – 2010-05-30 16:15:54
我也这么认为,处理递归值对于像F#这样渴望的语言来说是不平凡的任务......也许编译器应该像这样简单地限制[]用法。 –
ControlFlow
2010-05-30 16:29:11