I’m trying to find the correct name/documentation for defining “type functions” – any hint on where I can find it?
As an example, consider the following function for computing some norms of a vector:
function (v::Vector)(s::Symbol)
if s == :one
return sum(abs.(v))
elseif s == :two
return sqrt.(sum(v.^2))
elseif s == :inf
return maximum(abs.(v))
else
println("not defined")
end
end
Should be safe if you don’t do type piracy, but people prefer the new types to have callable instances instead of the preexisting types that didn’t have callable instances.
Thanks. I didn’t search for “object” since Julia is not “object oriented” in the standard way…
I’m no specialist on this, but I think an “object” is an instance/realization of a “class”.
So in Julia, “types” are somewhat close to a “class” (except for the methods vs. dispatch). Is there a generic Julia word for “instantiated”/“constructed” type? I.e., Vector is a type (“class”). Would v = [1,2,3] be referred to as an “object”? Or something else?
This is the typical meaning going way back to Simula 67’s introduction of OOP. However, “object” has since been used outside of OOP e.g. C. The Common Lisp Object System (CLOS) is considered OOP, but methods belong to multiply-dispatched generic functions instead of classes. That is indeed a major inspiration for Julia, but a key difference is that CLOS has class inheritance, but Julia’s concrete types cannot subtype another concrete type. That’s why Julia’s types are not classes; Go seems to draw that same line. Despite not having classes, Go and Javascript have method encapsulation and are still considered OOP. Lines are hard to draw and it’s hard to tell where the tipping point is, but Julia is far enough that nobody considers it OOP.
The computer science term for the result of instantiation is instance. The Julia documentation uses both terms interchangeably; the shortest example of this I could find: