如何消除有关递归引用的警告 [英] How to eliminate warning about recursive references

查看:77
本文介绍了如何消除有关递归引用的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个递归定义的对象.我从编译器收到此警告...

I've got a object that is defined recursively. I get this warning from the compiler...

在运行时,将通过使用延迟引用来检查对所定义对象的此和其他递归引用的初始化健全性.这是因为您要定义一个或多个递归对象,而不是递归函数. 可以通过使用"#nowarn"40""来抑制该警告.或"--nowarn:40".

This and other recursive references to the object(s) being defined will be checked for initialization-soundness at runtime through the use of a delayed reference. This is because you are defining one or more recursive objects, rather than recursive functions. This warning may be suppressed by using '#nowarn "40"' or '--nowarn:40'.

如何仅出于定义警告的功能而摆脱此警告?我不想为我的整个项目关闭这些警告.我尝试使用SuppressMessage属性(请参见下面的链接),但无法确定要分配给哪些属性 它导致消息消失.构建输出将其标识为警告FS0040.

How do I get rid of this warning FOR JUST the function in which it is defined? I don't want to turn off these warnings for my entire project. I've tried using the SuppressMessage attribute (see link below) but can't figure out what properties to assign to it to cause the message to disappear. The build output identifies this as warning FS0040.

http://msdn.microsoft.com/en-us/library/ms244717.aspx

这是生成警告的代码.我正在从邻接表构建图形数据结构.在输出中,您可以通过遵循单个顶点上的Neighbors函数从一个顶点遍历到另一个顶点.它是递归的,因为 我先创建了所有顶点,然后将它们放在地图中,但随后每个顶点都可以在包含它的地图中懒惰地找到它的邻居.

Here is the code that generates the warning. I'm building a graph data structure from an adjacency list. In the output you can traverse from one vertex to another by following the Neighbors function on a single vertex. It is recursive because I create all the vertexes up front and put them in a map, but then each vertex is able lazily find its neighbors in the map that contains it.

[<NoEquality>]
[<NoComparison>]
type IVertex<'Key,'Data,'Edge> =
    abstract member Data : 'Data
    abstract member Key : 'Key 
    abstract member Neighbors : ('Edge * IVertex<'Key,'Data,'Edge>) seq
    abstract member Neighbor : 'Edge -> IVertex<'Key,'Data,'Edge> option

[<NoEquality>]
[<NoComparison>]    
type IGraph<'Key,'Data,'Edge> =
    abstract member Vertices : IVertex<'Key,'Data,'Edge> seq
    abstract member TryFindVertex : 'Key -> IVertex<'Key,'Data,'Edge> option

let createGraph<'Key,'Data,'Edge when 'Key:comparison and 'Edge:comparison>(nodes) =
    let rec vertices:Map<'Key,IVertex<'Key,'Data,'Edge>> = 
        nodes
        |> Seq.map (fun (key, data, edges) -> 
            let verticesOfKey = lazy(
                edges 
                |> Seq.map (fun (edge, key) -> (edge, vertices |> Map.find key))
                |> Map.ofSeq)
            let vertex =
                { new IVertex<_,_,_> with
                    member this.Data = data
                    member this.Key = key
                    member this.Neighbors = verticesOfKey.Value |> Map.toSeq
                    member this.Neighbor edge = verticesOfKey.Value |> Map.tryFind edge
                }
            (key, vertex))
        |> Map.ofSeq
    { new IGraph<'Key,'Data,'Edge> with
        member this.Vertices = vertices |> Map.toSeq |> Seq.map (fun (key, vertex) -> vertex)
        member this.TryFindVertex key = vertices |> Map.tryFind key
    }


 


 

推荐答案

SuppressMessage属性由Code Analysis(以前为FxCop)和StyleCop使用;这与编译器无关.

The SuppressMessage attribute is used by Code Analysis (formerly, FxCop) and by StyleCop; it's not a compiler related thing.

当前对细粒度编译器消息控制的最佳F#提供是#nowarn具有文件剩余范围.

The best F# offers currently for fine-grain compiler message control is that #nowarn has a rest-of-file scope.


这篇关于如何消除有关递归引用的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆