gpt4 book ai didi

.net - 如何在F#中具有两个相互递归的结构类型?

转载 作者:行者123 更新时间:2023-12-04 16:53:03 24 4
gpt4 key购买 nike

以下代码无法编译:

[<Struct>]
type Point(x:int, y:int) =
member __.X = x
member __.Y = y
member __.Edges = ArrayList<Edge>()
[<Struct>]
and Edge(target:Point, cost:int) =
member __.Target = target
member __.Cost = cost

问题出在 [<Struct>]属性上,该属性似乎与“and”结构冲突。

我应该怎么做呢?我知道我可以选择完成以下任务
type Point(x:int, y:int) =
struct
member __.X = x
member __.Y = y
member __.Edges = new ArrayList<Edge>()
end
and Edge(target:Point, cost:int) =
struct
member __.Target = target
member __.Cost = cost
end

但我喜欢 [<Struct>]简洁。

谢谢

最佳答案

将属性定义移到and token 之后

and [<Struct>] Edge(target:Point, cost:int) =

关于.net - 如何在F#中具有两个相互递归的结构类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21506693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com