Excuse me, does motoko have function overloading?

Excuse me, is there any function overloading in motoko, and is there any function overloading similar to java and solidity?

func calc(v:nat):async nat{};
func calc(v:int):async int{};

You know that’s a good question. I actually never have tried this personally.

Did you try the Motoko Playground and see if it compiles?

https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/

(That’s how I usually explore and learn languages, specially Motoko)

https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=2926715365

Yes, I see that it is not supported, but I want to know if there are other ways to achieve it

1 Like

Oh I see I’m sorry I misunderstood your question. Let me ping some of the Motoko folks to see what they recommend

No, there is no function overloading. We consider that a feature. :wink: It would not work particularly well with Motoko’s more expressive type system either. It also wouldn’t work for actor methods, because the IC distinguishes messages by name only.

5 Likes