Redefining methods in Base

Just curious. It looks like that something as Base.:+(a,b)= a*b has no effect.
Does Julia not allow redefining methods in Base? If so, what would be rationale behind it?

Do you really want to get 5+6 as 30?

Just guessing here, but you are probably just testing the effect incorrectly, e.g. Int + Int has a more special method that will be called even after your definition.

3 Likes

No not really. :slight_smile:
If such thing is allowed, it would be possible to define such as Base.:+(a::CustomType, b::CustomType) as you wish.

Oh I see. Base.:+(a::CustomType, b::CustomType) does work indeed. Int + Int seems to be handled specially.

It’s not special, it’s multiple dispatch! One of Julia’s not-so-secret sauces Methods · The Julia Language

2 Likes

You can do Base.:+(a::Int, b::Int) = a * b but Julia won’t survive long enough for you to enjoy it, since it totally breaks the internals.

3 Likes

@kevbonham, @GunnarFarneback, A-ha, yes, indeed. Thanks!