user25004
user25004

Reputation: 2048

Julia function argument type def

I faced some problem regarding defining the type of arguments for a function in Julia. From one hand, the code would be faster to run if the type is defined: for example Int64 for an integer number. On the other hand, passing a simple number to the function would needs type cast every time I call the function, e.g. by calling:

convert(a, Int64)

That seems to be an overkill. what is the advice for good style?

Upvotes: 0

Views: 498

Answers (1)

Scott Jones
Scott Jones

Reputation: 1750

With Julia, it's not generally true that specifying the type for a function's argument(s) will make it faster. If the argument has no type (i.e. Any), or has just an abstract type (for example, Integer instead of Int64, Julia can generate methods for whatever concrete types are actually used to call the function, instead of having to do any conversion. BTW, the syntax is actually convert(Int64, a), the type you wish to convert to comes first.

Upvotes: 4

Related Questions