How to use more complex type inheritance in Julia

I am trying to use the regular type Any in the following functions:

function f(arr::Array{Tuple{ASCIIString , Any},1})
arr[1]
end

It applies to

f([("a ",1), ("b","x")])

But in

f([("a",1)] )

This will not work. Some people would think that Int is actually Any, but obviously not.

How to work in the latter case? I am interested in a general solution, because this problem has appeared in many places in Julia, the above is just a simple example. Should I use all types of alliances in the tuple instead of Any?

The type parameters in Julia are unchanged, please refer to http://julia.readthedocs. org/en/latest/manual/types/#parametric-composite-types. To get the behavior you are after, you need to parameterize the function with type parameters:

function f{T <: Tuple{ASCIIString, Any}}(arr::Array{T,1})
arr[1]
end

I tried to use the regular type Any in the following functions:

function f(arr::Array{Tuple{ASCIIString, Any},1} )
arr[1]
end

It applies to

f([("a",1), ( "b","x")])

But in

f([("a",1)])

< p>This won’t work. Some people would think that Int is actually Any, but obviously not.

How to work in the latter case? I am interested in a general solution, because this problem has appeared in many places in Julia, the above is just a simple example. Should I use all types of alliances in the tuple instead of Any?

The type parameters in Julia are unchanged, please refer to http://julia.readthedocs.org/en/latest/manual/types/#parametric -composite-types. To get the behavior you are after, you need to parameterize the function with type parameters:

function f{T <: Tuple{ASCIIString , Any}}(arr::Array{T,1})
arr[1]
end

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2807 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.