F #에서 기본값 "="(같음) 연산자에 대한 질문이 있습니다. 그것은 사용자가 정의한 union 유형을 비교할 수있게합니다. 문제는 그것의 복잡성은 무엇인가?F #이 연산자 복잡성과 같습니다.
let a : Tree<int> = Node (Node (Node (Leaf 1, Leaf 2), Node (Leaf 3, Node (Leaf 4, Leaf 5))), Node (Leaf 6, Nil))
let b : Tree<int> = Node (Node (Node (Leaf 1, Leaf 2), Node (Leaf 3, Node (Leaf 4, Leaf 5))), Node (Leaf 6, Nil))
let c : Tree<int> = Node (Node (Node (Leaf 1, Leaf 2), Nil), Node (Node (Leaf 3, Node (Leaf 4, Leaf 5)), Leaf 6))
그것은 분명이 코드 있음 :
a = b: true
a = c: false
a = a: true
:
printfn "a = b: %b" (a = b)
printfn "a = c: %b" (a = c)
printfn "a = a: %b" (a = a)
이 출력을 생성
type Tree<'a> =
| Nil
| Leaf of 'a
| Node of Tree<'a> * Tree<'a>
및 다음 나무 : 예를 들어, 다음과 같은 유형을 살펴 보자
나는 "a = b "이고"a = c "comparsions은 선형 시간이 걸립니다. 그러나 "a = a"은 어떨까요? 그것은 일정한 경우 더 복잡한 구조에 대해 무엇을, 그 같은 :
let d : Tree<int> = Node (a, c)
let e : Tree<int> = Node (a, c)
는 전체 D 및 전자 구조를 통해 갈 것인가 아니면 "= A A"에서와 중지됩니다 "C = c "?
Downvoter, 관심있는 댓글? – svick
나는 downvoter가 아니지만, "평등하게 구현 된 'Equals'"는 F # 유니온에는 적용되지 않습니다. – Daniel
왜 안 되니? 그것은 그것과 똑같이 행동합니다. – svick