Annotating function arguments
In a statically typed language without any polymorphism, such as C or Fortran, every argument must be specified with the exact type. Julia, however, is dynamically typed and supports duck typing—if it walks like a duck and quacks like a duck, then it is a duck. Type information is not required in the source code at all. Instead, the compiler looks at runtime types that you pass into the function and compiles the appropriate method specialized for those types. The process of deducing types throughout a method body based on the argument types is called type inference.
Therefore, there is no need to annotate function arguments with type information at all. People sometimes get the impression that putting type annotations ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access