[<Struct;CustomComparison>]
type Node<'a>(expr:'a, symbol:int) =
member x.Expression = expr
member x.Symbol = symbol
override x.ToString() = sprintf "%A" expr
override x.GetHashCode() = symbol
override x.Equals(y) =
match y with
| :? Node<'a> as y -> symbol = y.Symbol
| _ -> failwith "Invalid equality for Node."
interface IComparable with
member x.CompareTo(y) =
match y with
| :? Node<'a> as y -> compare symbol y.Symbol
| _ -> failwith "Invalid comparison for Node."
The above does not work and the error messages are confusing to me. I am using the Node
class to hold other nodes in a AST and am wondering whether turning it into a struct would speed up the compiler I am working on.
The type does typecheck without the IComparable
interface, so I am asking specifically about comparison.