Overloading base operator from module

tldr: add import Base: * inside your module.

Long version:
Julia already has a function called * (which does various kinds of multiplication) defined in Base, (Base is the set of functions that Julia ships with).
Calling function *(...) creates a new function called *. That doesn’t change or delete the function that Julia already has, but it does create an ambiguity: when you call *(x, y), (or equivalently, x * y), do you want the function * in Base, or the one in your module? That’s what the error says: “uses of it in module Main must be qualified” means: "you will now have to say Base.*(x, y) or JulHDG.*(x, y) every time you do multiplication. You don’t want that.

But you don’t want to have to choose. You want the ‘correct’ version of * to be automatically chosen for a particular input type, right? That’s the whole promise of Julia. To do that, you need to tell Julia that you’re not defining a brand-new function called *, but just adding some new behavior to the existing *. Importing * from Base tells Julia exactly that.

7 Likes