I want to define an interface for any coordinate-type-thing which implements a Distance() method that can be used to calculate distance (maybe cartesian, maybe chronological, whatever) from another coordinate-type-thing of the same type.
This is the general idea:
type Distancer interface {
Distance(other interface{}) int
}
This doesn't provide type-safety for the argument to Distance(), though, which must be of the same type. For example, I might have a ParticularTime struct that implements Distance(); passing another ParticularTime object as the argument makes sense, but passing a ParticularLocation doesn't make sense at all.
I suspect this could be caught at compile-time at least in some cases, e.g. this is obviously wrong:
x := ParticularLocation{}
y := ParticularTime{}
distance := x.Distance(y)
Is there any way to express this restriction? Or do I have to do runtime type-checking inside every implementation of Distance() ?
Am I thinking about this problem the wrong way?