Yes other languages have features like extensions. As @hnh points out C# has a very similar feature
It also makes it clear this feature is not "monkey patching"
Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type
To put it another way extensions are more like a syntactic sugar. Given the example in the question, Double, you could just make a function that takes a Double (as shown in the question)
func mm(a: Double) -> Double {
return a * 1_000.0
}
And then you could call it directly
var foo = 12.34;
print("One meter is \(mm(foo)) millimeters")
What effectively happens with extensions in both C# and Swift is the extension tells the compiler to translate behind the scenes
someDouble.mm()
into
mm(someDouble)
or in our case more like
__extension_for_type_Double_mm(someDouble as self)
So, nothing is patched.
This also means you can have more than one mm
extension from different modules and choose which one to use per file by only importing that module in that file where as some other file can import another module with another extension for the same type with the same name. This is not possible with monkey patching because the object or its class/prototype gets patched (something actually changes). Here, nothing changes, it's just syntactic sugar for calling a stand alone function.
This means features like monkey-patching in Ruby and JavaScript are not the same as extensions.