4 ms·
Julia does not have optional typing. Type annotations are used to specify what function implementation applies to a specific argument types. E.g. if I write a
by socialdemocrat 7y ago
Julia does not have optional typing. Type annotations are used to specify what function implementation applies to a specific argument types.
E.g. if I write a function definition as foo(x::Int, y::String) that means that code is run whenever the first to arguments are Int and String. While if another definition is specified as foo(x::DateTime, y::Float64), means that this other definition applies to when the arguments are dates and floating point values.
Types are not used to improve performance. Rather they are a necessity to tell Julia what chunk of code should be run for particular types.
Often you use it to narrow down what types a function applies to. E.g. bar(x::Number) means bar function requires some sort of number. You cannot provide a string. However the compiler will not warn you if you use a string in a bar call. Instead you get an exception at runtime telling you there are no variants of bar, which takes string as argument.
- dmix 7y agoMultiple dispatch is so helpful when designing programs and interfaces. It’s one of the biggest things I miss from Erlang/Elixir when I’m using JS/Ruby, besides pattern matching and function guards.