I'm new to julia and I have not been able to find an explanation of where
that fully makes sense to me.
So I understand that for example
function f(x::T, y::T) where {T<:Number} = true
is requiring that both the x and y parameters be numeric types of some sort.
But then there are other functions that will look like function f(X::AbstractMatrix{T}) where T
without any specification of what T is supposed to be. Can someone explain what that is doing and when I would want to use this syntax?
A return type can be specified in the function declaration using the :: operator. This converts the return value to the specified type. This function will always return an Int8 regardless of the types of x and y .
Using all of a function's arguments to choose which method should be invoked, rather than just the first, is known as multiple dispatch.
an exclamation mark is a prefix operator for logical negation ("not") a! function names that end with an exclamation mark modify one or more of their arguments by convention. # the number sign (or hash or pound) character begins single line comments.
type and immutable are valid up to julia 0.6, mutable struct and struct are the names of the same objects in julia 0.6 and forward. mutable in mutable struct means that the fields can change - which is actually fairly rarely used so being immutable is the default. mutable struct 's are slower than struct s.
where T
without anything else is just where {T<:Any}
in other words, it's true for all T
, but Julia needs you to write something so that `T is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With