小编kon*_*002的帖子

使用内部委托类型编译lambda表达式

如果委托类型是内部的,我在为F#中的属性getter编译lambda表达式时遇到一些麻烦.这就是函数的样子:

// if I omit the 'internal' here everything works as expected
module internal ReflectionHelpers =

    open System
    open System.Linq.Expressions
    open System.Reflection

    // it makes no difference if this delegate type is defined outside
    // of the module and marked as 'internal'
    type GetterFunc<'T> = delegate of 'T -> obj

    /// Build a getter expression function for the
    /// specified PropertyInfo
    let getGetter<'a> (p : PropertyInfo) =
        let inst = Expression.Parameter(p.DeclaringType, "i")
        let prop = Expression.Property(inst, p)
        let …
Run Code Online (Sandbox Code Playgroud)

.net reflection f#

4
推荐指数
1
解决办法
527
查看次数

F#中的字符串解析 - 生成的IL

我在F#中编写了一些小的字符串解析函数 - 以便更好地了解F#并了解如何使用它来解决此类任务.我尝试遍历字符串并通过递归搜索特定字符.

逻辑确实有效,但在我看来,生成的版本构建的IL代码(启用了优化)确实看起来很奇怪.所以我想有更好的方法在F#中以高效的方式编写这些东西.

这是解析函数的一部分:

let eatTag (input : string) index =
    let len = input.Length
    let nothing = 0, null, TagType.Open

    // more functions used in the same way
    // ...

    let rec findName i =
        if i >= len then nothing
        else
            let chr = input.[i]
            if isWhitespace chr then
                findName (i+1)
            elif chr = '/' then
                getName (i+1) (i+1) true
            else getName (i+1) i false

    let rec findStart i =
        if i >= len then nothing
        elif …
Run Code Online (Sandbox Code Playgroud)

.net f# il parsing

3
推荐指数
2
解决办法
581
查看次数

标签 统计

.net ×2

f# ×2

il ×1

parsing ×1

reflection ×1