This project is read-only.
Using Structural Equality

Category:
Equality, Comparison and Hashing
Description: F# supports structural comparison and equality of values with the same type. This sample shows the results of some simple structural comparison operations.
Code:
let ComparisonSample1() =
let show a b =
printfn "%A < %A: %b" a b (a < b)
printfn "%A = %A: %b" a b (a = b)
printfn "%A > %A: %b" a b (a > b)

show 1 2;
show 2 2;
show "1" "2"
show "abb" "abc"
show "aBc" "ABB" // case-sensitive
show None (Some 1);
show None None;
show (Some 0) (Some 1);
show (Some 1) (Some 1);
show [1;2;3] [1;2;2];
show [] [1;2;2]


Execution Result:
1 < 2: true
1 = 2: false
1 > 2: false
2 < 2: false
2 = 2: true
2 > 2: false
"1" < "2": true
"1" = "2": false
"1" > "2": false
"abb" < "abc": true
"abb" = "abc": false
"abb" > "abc": false
"aBc" < "ABB": false
"aBc" = "ABB": false
"aBc" > "ABB": true
< Some 1: true
= Some 1: false
> Some 1: false
< : false
= : true
> : false
Some 0 < Some 1: true
Some 0 = Some 1: false
Some 0 > Some 1: false
Some 1 < Some 1: false
Some 1 = Some 1: true
Some 1 > Some 1: false
[1; 2; 3] < [1; 2; 2]: false
[1; 2; 3] = [1; 2; 2]: false
[1; 2; 3] > [1; 2; 2]: true
[] < [1; 2; 2]: true
[] = [1; 2; 2]: false
[] > [1; 2; 2]: false

Last edited Sep 14, 2011 at 3:56 AM by ttliu2000, version 1

Comments

No comments yet.