kol*_*osy 4 reflection f# quotations
我正在为SQL写一个F#dsl(http://github.com/kolosy/furious).
select语句如下所示:
type person = {
personId: string
firstname: string
lastname: string
homeAddress: address
workAddress: address
altAddresses: address seq
}
and address = {
addressId: string
street1: string
zip: string
}
let (neighbor: person seq) =
db.Yield <@ Seq.filter (fun p -> p.homeAddress.zip = '60614') @>
Run Code Online (Sandbox Code Playgroud)
显而易见(而且很愚蠢)的问题是......如何对报价进行参数化?
如果我只是喜欢:
let z = "60614"
let (neighbor: person seq) =
db.Yield <@ Seq.filter (fun p -> p.homeAddress.zip = z) @>
Run Code Online (Sandbox Code Playgroud)
然后z被解析为静态属性访问器(PropertyGet(None, String z, [])).我需要一些东西让我只根据报价检索变量/ let绑定的值.想法?
报价不是我的强项,但请查看其中的区别:
let z = "60614"
let foo = <@ List.filter (fun s -> s = z) @>
printfn "%A" foo
let foo2 =
let z = z
<@ List.filter (fun s -> s = z) @>
printfn "%A" foo2
Run Code Online (Sandbox Code Playgroud)
我想也许让'z'在表达式中是局部的意味着捕获值,而不是属性引用.