Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. [<StructuralEquality;StructuralComparison>]
  2. type SomeType = {
  3. Value : int
  4. }
  5.  
  6. let someTypeAsIEquatable = { Value = 3 } :> System.IEquatable<SomeType>
  7. someTypeAsIEquatable.Equals({Value = 3}) |> ignore // calls Equals(SomeType) directly
  8.  
  9. { Value = 3 }.Equals({Value = 4})
  10.  
  11. public struct Vector2f : IEquatable<Vector2f>
  12.  
  13. [<Struct;CustomEquality;NoComparison>]
  14. type MyVal =
  15. val X : int
  16. new(x) = { X = x }
  17. override this.Equals(yobj) =
  18. match yobj with
  19. | :? MyVal as y -> y.X = this.X
  20. | _ -> false
  21. interface System.IEquatable<MyVal> with
  22. member this.Equals(other) =
  23. other.X = this.X
  24.  
  25. [<Struct>]
  26. type MyVal =
  27. val X : int
  28. new(x) = { X = x }
  29.  
  30. for i in 0 .. 1000000 do
  31. (MyVal(i) = MyVal(i + 1)) |> ignore;;
  32. Réel : 00:00:00.008, Processeur : 00:00:00.015, GC gén0: 4, gén1: 1, gén2: 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement