Posts

Showing posts with the label customequality

Using a Map with a non-comparable object

Using a Map with a non-comparable object I have Job type, equality is defined as the Job's ID being equal. There should never be two jobs with the same ID. They aren't comparable though, one job isn't more or less than another, only equal or not. Job type JobId = JobId of string [<CustomEquality; NoComparison>] type Job = { Id: JobId } with interface System.IEquatable<Job> with member x.Equals y = x.Id = y.Id type Resource = { Id: string Capacity: float Usage: Map<Job,float> } The Map needs a comparison though. Map Map IDictionary I would advise you to use JobId as the map key, not Job , and don't override Equals , just check for ID equality. It's a more functional/idiomatic F# style: data is just dumb data. And it makes this particular problem go away. – TheQuickBrownFox Jul 2 at 9:37 ...