# \#type

**URL:** https://discourse.julialang.org/tag/type/116.md?match_all_tags=true&page=4&tags%5B%5D=type

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 5

---

## [What is the diffence between abstract type and singleton type](https://discourse.julialang.org/t/what-is-the-diffence-between-abstract-type-and-singleton-type/94258)

<div class="topic-metadata">

**Author:** [@zhangwfjh](https://discourse.julialang.org/u/zhangwfjh)\
**Replies:** 4\
**Last updated:** [February 8, 2023, 12:04pm UTC](https://discourse.julialang.org/t/what-is-the-diffence-between-abstract-type-and-singleton-type/94258 "2023-02-08T12:04:15Z")

</div>

I think both abstract type and singleton type are used for multiple dispatching. So what are their differences and how do I choose? I know that abstract type cannot be instantialized.

---

## [Understanding specialized methods for field access](https://discourse.julialang.org/t/understanding-specialized-methods-for-field-access/94136)

<div class="topic-metadata">

**Author:** [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Replies:** 7\
**Last updated:** [February 7, 2023, 12:00pm UTC](https://discourse.julialang.org/t/understanding-specialized-methods-for-field-access/94136 "2023-02-07T12:00:31Z")

</div>

Hi! Since this is my first post, let me say that I have worked with Julia for some work and hobby projects until now, and that I really like the language and its possibilities – and its amazing community, sharing their …

---

## [Subtype for UnionAll](https://discourse.julialang.org/t/subtype-for-unionall/93896)

<div class="topic-metadata">

**Author:** [@romatead](https://discourse.julialang.org/u/romatead)\
**Replies:** 1\
**Last updated:** [February 2, 2023, 1:10am UTC](https://discourse.julialang.org/t/subtype-for-unionall/93896 "2023-02-02T01:10:10Z")

</div>

Dear all, I would like to define ab abstract type T1{T} as a UnionAll and to be a subtype of an abstract type T0{T}. How can I define a type with the const syntax as a subtype of an abstract type ? The following does n…

---

## [How do I define my own type based on Julia's pre-existing type?](https://discourse.julialang.org/t/how-do-i-define-my-own-type-based-on-julias-pre-existing-type/93835)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 4\
**Last updated:** [January 31, 2023, 8:54pm UTC](https://discourse.julialang.org/t/how-do-i-define-my-own-type-based-on-julias-pre-existing-type/93835 "2023-01-31T20:54:49Z")

</div>

Hello! I am trying to perform a simple experiment and need some help. I wish to make a copy of the AbstractVector type as such: struct AbstractVectorCopy{T} \<: AbstractVector{T} field::AbstractVector{T} end Then…

---

## [Vararg (sub)type parameter undocumented dispatch weirdness](https://discourse.julialang.org/t/vararg-sub-type-parameter-undocumented-dispatch-weirdness/87110)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 7\
**Last updated:** [January 29, 2023, 12:02am UTC](https://discourse.julialang.org/t/vararg-sub-type-parameter-undocumented-dispatch-weirdness/87110 "2023-01-29T00:02:59Z")

</div>

a1(::Integer...) = nothing a2(::I...) where {I \<: Integer} = nothing a3(::Vararg{Integer}) = nothing a4(::Vararg{\<:Integer}) = nothing a5(::Vararg{I}) where {I \<: Integer} = nothing b3(::NTuple{n, Integer}) where {n} = n…

---

## [Is accessing the \`instance\` field of a singleton type supported usage?](https://discourse.julialang.org/t/is-accessing-the-instance-field-of-a-singleton-type-supported-usage/93671)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 2\
**Last updated:** [January 28, 2023, 12:48am UTC](https://discourse.julialang.org/t/is-accessing-the-instance-field-of-a-singleton-type-supported-usage/93671 "2023-01-28T00:48:56Z")

</div>

The above technique is very useful in rare cases, but I wonder whether it’s supported? I don’t think it’s documented. For example; is the below guaranteed to work with future Julia versions? julia\> Tuple{Nothing, Noth…

---

## [Question on Idiomatic Julia, Traits, and Types](https://discourse.julialang.org/t/question-on-idiomatic-julia-traits-and-types/93484)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 6\
**Last updated:** [January 25, 2023, 7:36am UTC](https://discourse.julialang.org/t/question-on-idiomatic-julia-traits-and-types/93484 "2023-01-25T07:36:39Z")

</div>

I’m trying to better learn and understand how to write idiomatic Julia. Please consider the following example. I have a some types defined as follows. abstract type MyAbstractType end Base.@kwdef struct MyStruct\_1D \<:…

---

## [Creating a custom Dict clone for formatted printing?](https://discourse.julialang.org/t/creating-a-custom-dict-clone-for-formatted-printing/92975)

<div class="topic-metadata">

**Author:** [@daharn](https://discourse.julialang.org/u/daharn)\
**Replies:** 2\
**Last updated:** [January 19, 2023, 11:54pm UTC](https://discourse.julialang.org/t/creating-a-custom-dict-clone-for-formatted-printing/92975 "2023-01-19T23:54:27Z")

</div>

I want to be able to print the key-value pairs from a Dict-like object in a certain formatted way. I see two ways to do this: Either write a my\_print(dct::Dict) function that does this and use a regular Dict to store th…

---

## [How to broadcast a scalar multiplication through a Mesh?](https://discourse.julialang.org/t/how-to-broadcast-a-scalar-multiplication-through-a-mesh/93038)

<div class="topic-metadata">

**Author:** [@g2g](https://discourse.julialang.org/u/g2g)\
**Replies:** 2\
**Last updated:** [January 17, 2023, 1:07am UTC](https://discourse.julialang.org/t/how-to-broadcast-a-scalar-multiplication-through-a-mesh/93038 "2023-01-17T01:07:18Z")

</div>

I’m trying to port a JavaScript 3D slicer example to Julia. The example loads a 3D model of a bunny (from https://enkimute.github.io/ganja.js/examples/bunny.obj having 5002 triangle faces) and then calculates horizontal …

---

## [How to dispatch on a Tuple with unknown length, but elements have same abstract type?](https://discourse.julialang.org/t/how-to-dispatch-on-a-tuple-with-unknown-length-but-elements-have-same-abstract-type/93017)

<div class="topic-metadata">

**Author:** [@zsoerenm](https://discourse.julialang.org/u/zsoerenm)\
**Replies:** 4\
**Last updated:** [January 16, 2023, 11:42am UTC](https://discourse.julialang.org/t/how-to-dispatch-on-a-tuple-with-unknown-length-but-elements-have-same-abstract-type/93017 "2023-01-16T11:42:33Z")

</div>

Consider this example: a = (complex(1,2), complex(1.0, 2.0)) The length of a is not fixed to 2, but could be arbitrary. Is there a way to dispatch on this? I tried a isa NTuple{N, \<: Complex} where N but this is ob…

---

## [Arbitrary Precision Optimization](https://discourse.julialang.org/t/arbitrary-precision-optimization/92803)

<div class="topic-metadata">

**Author:** [@csmarra](https://discourse.julialang.org/u/csmarra)\
**Replies:** 2\
**Last updated:** [January 11, 2023, 7:21pm UTC](https://discourse.julialang.org/t/arbitrary-precision-optimization/92803 "2023-01-11T19:21:19Z")

</div>

Hi, I am trying to perform a function minimization with BigFloat numbers. However, it seems that I cannot get it to work. I am using the BlackBoxOptim.jl package. Is there a way to do that? As an example, I tried to do…

---

## [Retrieving the contents of C composite types](https://discourse.julialang.org/t/retrieving-the-contents-of-c-composite-types/92749)

<div class="topic-metadata">

**Author:** [@mmv](https://discourse.julialang.org/u/mmv)\
**Replies:** 14\
**Last updated:** [January 11, 2023, 3:17pm UTC](https://discourse.julialang.org/t/retrieving-the-contents-of-c-composite-types/92749 "2023-01-11T15:17:43Z")

</div>

Hi! I wrote a wrapper to a C function that defines its output as a structure, defined as follows in the associated .h file: typedef struct { double lat; double lon; } MTKt\_GeoCoord; typedef struct { MTKt\_GeoCoor…

---

## [Why can't I use Vector{Int64} with functions expecting Vector{Integer}?](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779)

<div class="topic-metadata">

**Author:** [@Titas22](https://discourse.julialang.org/u/Titas22)\
**Replies:** 4\
**Last updated:** [December 17, 2022, 5:59pm UTC](https://discourse.julialang.org/t/why-cant-i-use-vector-int64-with-functions-expecting-vector-integer/91779 "2022-12-17T17:59:47Z")

</div>

Hi, I was trying to define a function that would work on all integer types, and could not get it to work when the input is matrix or vector. functions taking in single value of Int64 or Integer work fine. But if I call…

---

## [Obtaining the type of the state object returned by Iterate](https://discourse.julialang.org/t/obtaining-the-type-of-the-state-object-returned-by-iterate/59190)

<div class="topic-metadata">

**Author:** [@Olof\_Salberger](https://discourse.julialang.org/u/Olof_Salberger)\
**Replies:** 4\
**Last updated:** [December 17, 2022, 12:15pm UTC](https://discourse.julialang.org/t/obtaining-the-type-of-the-state-object-returned-by-iterate/59190 "2022-12-17T12:15:35Z")

</div>

An issue I’ve run into is that if you have a container type T, in general it isn’t possible to obtain the type of state returned by iterate in the same way as you can get eltype(T) since there is no (let’s call it iterat…

---

## [Convert Numpy Arrays to Julia Arrays by Default PythonCall/JuliaCall](https://discourse.julialang.org/t/convert-numpy-arrays-to-julia-arrays-by-default-pythoncall-juliacall/90671)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 5\
**Last updated:** [November 28, 2022, 9:51pm UTC](https://discourse.julialang.org/t/convert-numpy-arrays-to-julia-arrays-by-default-pythoncall-juliacall/90671 "2022-11-28T21:51:14Z")

</div>

I am currently writing an interface between a Python program and a Julia Package; I would like to call the functions in the Julia package from Python. The functions in the Julia package all have type declarations, and fo…

---

## [Extract function from function type](https://discourse.julialang.org/t/extract-function-from-function-type/90651)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 13\
**Last updated:** [November 22, 2022, 10:59pm UTC](https://discourse.julialang.org/t/extract-function-from-function-type/90651 "2022-11-22T22:59:53Z")

</div>

Consider the following: foo(x) = x foo\_type = foo |\> typeof # Don't know how to implement but I know what I want it to do # Example: default(foo\_type) -\> foo default(::Type{T}) where T \<: Function = ??? # The followin…

---

## [Unable to use Types from Graphs.jl and GridGraphs.jl in Jupyter Notebook](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913)

<div class="topic-metadata">

**Author:** [@MarawanEmara](https://discourse.julialang.org/u/MarawanEmara)\
**Replies:** 12\
**Last updated:** [November 19, 2022, 5:47pm UTC](https://discourse.julialang.org/t/unable-to-use-types-from-graphs-jl-and-gridgraphs-jl-in-jupyter-notebook/88913 "2022-11-19T17:47:03Z")

</div>

Hello. I am pretty new to Julia and attempting to replicate a tutorial for InferOpt.jl (Tutorial in question is linked here: Tutorial · InferOpt.jl). I have already installed the appropriate packages for using Julia in…

---

## [How to use type parameter variables across multiple parametric types](https://discourse.julialang.org/t/how-to-use-type-parameter-variables-across-multiple-parametric-types/90162)

<div class="topic-metadata">

**Author:** [@christophE](https://discourse.julialang.org/u/christophE)\
**Replies:** 10\
**Last updated:** [November 12, 2022, 4:45pm UTC](https://discourse.julialang.org/t/how-to-use-type-parameter-variables-across-multiple-parametric-types/90162 "2022-11-12T16:45:33Z")

</div>

Hello Julia folk, I am testing something very simple, a dot product, and I want to ensure, it gets two arrays (or vectors) of the same length. This attempt does not work: function dot\_product{N::UInt64}(vec1::Array{Flo…

---

## [Union all Types](https://discourse.julialang.org/t/union-all-types/90087)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 2\
**Last updated:** [November 11, 2022, 2:57am UTC](https://discourse.julialang.org/t/union-all-types/90087 "2022-11-11T02:57:35Z")

</div>

Pair{Symbol,Number} Would be a nice short-hand for Pair{Symbol,T} where T\<:Number is there a reason it can’t be written like this? it would be nice to write f(x::Pair{Symbol,Number}) = 1 instead of f(x::Pair{Sym…

---

## [@inbounds equivalent for type assertions](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 3:31pm UTC](https://discourse.julialang.org/t/inbounds-equivalent-for-type-assertions/89107 "2022-11-08T15:31:17Z")

</div>

Is there an @inbounds equivalent for type assertions? That is allow the compiler to aggressively compile a specialization based on a type assertion that is unsafe if the type is not correct?

---

## [What are Julia's coordinates in the λ-cube?](https://discourse.julialang.org/t/what-are-julias-coordinates-in-the-cube/89883)

<div class="topic-metadata">

**Author:** [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Replies:** 6\
**Last updated:** [November 7, 2022, 4:51pm UTC](https://discourse.julialang.org/t/what-are-julias-coordinates-in-the-cube/89883 "2022-11-07T16:51:51Z")

</div>

I was sidetracked procrastinating reading a thread about using “{}”. here and popping out a new thread. My vote was to make where statements more expressive by doing type calculations inside blocks deliminated by {} so …

---

## [(why) is there no Abstract Collection type](https://discourse.julialang.org/t/why-is-there-no-abstract-collection-type/89233)

<div class="topic-metadata">

**Author:** [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Replies:** 11\
**Last updated:** [November 4, 2022, 5:13pm UTC](https://discourse.julialang.org/t/why-is-there-no-abstract-collection-type/89233 "2022-11-04T17:13:22Z")

</div>

Hi everyone, A common code pattern seems to be: function thingthatiterates(x, collection::AbstractArray) for i in collection ... end end Now in some cases, it might be better to use something non-allocating …

---

## [Can typeof() return an alias?](https://discourse.julialang.org/t/can-typeof-return-an-alias/89412)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [October 28, 2022, 6:58am UTC](https://discourse.julialang.org/t/can-typeof-return-an-alias/89412 "2022-10-28T06:58:11Z")

</div>

Is it possible to have a type alias where typeof() returns the alias rather than the base type e.g. XString = String x::XString = "ab" typeof(x) # gives XString not String Use Case The below code produc…

---

## [Constrain type to variable sized union](https://discourse.julialang.org/t/constrain-type-to-variable-sized-union/89206)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 2\
**Last updated:** [October 24, 2022, 9:07pm UTC](https://discourse.julialang.org/t/constrain-type-to-variable-sized-union/89206 "2022-10-24T21:07:39Z")

</div>

I want to constrain a type parameter to be a variable sized union whose elements are concrete types of another parametric type. For example: struct Foo{T} ... end struct Bar{T \<: Union{Vararg{Foo}}} a::T end T…

---

## [Union Splitting Guarantees](https://discourse.julialang.org/t/union-splitting-guarantees/89210)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 2\
**Last updated:** [October 24, 2022, 8:54pm UTC](https://discourse.julialang.org/t/union-splitting-guarantees/89210 "2022-10-24T20:54:19Z")

</div>

I have some low level questions about union splitting 1.) If even one type in the union is abstract will union splitting not kick in? Or will there be branches created for at least the concrete types in the union. For e…

---

## [Constrain type to be concrete subtype](https://discourse.julialang.org/t/constrain-type-to-be-concrete-subtype/89207)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 3\
**Last updated:** [October 24, 2022, 8:50pm UTC](https://discourse.julialang.org/t/constrain-type-to-be-concrete-subtype/89207 "2022-10-24T20:50:12Z")

</div>

Suppose I have the following struct: struct Foo{T \<: Real} a::T end I am still able to construct a Foo as: Foo{Real}(20). Is there a way to demand that the type parameter be a concrete type such as Int64, Float64, …

---

## [Use function on type parameter to decide struct field type at compile time](https://discourse.julialang.org/t/use-function-on-type-parameter-to-decide-struct-field-type-at-compile-time/89172)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 3\
**Last updated:** [October 24, 2022, 4:47am UTC](https://discourse.julialang.org/t/use-function-on-type-parameter-to-decide-struct-field-type-at-compile-time/89172 "2022-10-24T04:47:07Z")

</div>

This code does not work, but I want to do something like the following (the general idea should be clear): map\_type(::Type{String}) = Int64 map\_type(::Type{Int64}) = String struct Foo{T} a::map\_type(T) end Basical…

---

## [Are functions that operate only on types computed at compile time](https://discourse.julialang.org/t/are-functions-that-operate-only-on-types-computed-at-compile-time/89161)

<div class="topic-metadata">

**Author:** [@HashBrown](https://discourse.julialang.org/u/HashBrown)\
**Replies:** 2\
**Last updated:** [October 23, 2022, 9:30pm UTC](https://discourse.julialang.org/t/are-functions-that-operate-only-on-types-computed-at-compile-time/89161 "2022-10-23T21:30:19Z")

</div>

Suppose I have the following function get\_first\_type(::Type{T}) where T \<: Tuple = begin fieldtypes(T)\[1\] end If another function calls this function with one of its input type parameters, will this function be co…

---

## [Supertype in Julia](https://discourse.julialang.org/t/supertype-in-julia/88930)

<div class="topic-metadata">

**Author:** [@Fourier](https://discourse.julialang.org/u/Fourier)\
**Replies:** 15\
**Last updated:** [October 19, 2022, 3:29pm UTC](https://discourse.julialang.org/t/supertype-in-julia/88930 "2022-10-19T15:29:34Z")

</div>

Imagine someone else has implemented something, say a type and a function: struct Foo a::Int end function bar(x::Foo) return x.a end I would like to build on what he has implemented, I would like to use the fu…

---

## [How to directly specify datatype when reading from excel? Matrix{Any} to Vector{Int64}](https://discourse.julialang.org/t/how-to-directly-specify-datatype-when-reading-from-excel-matrix-any-to-vector-int64/88853)

<div class="topic-metadata">

**Author:** [@Mike\_comen](https://discourse.julialang.org/u/Mike_comen)\
**Replies:** 4\
**Last updated:** [October 18, 2022, 9:51pm UTC](https://discourse.julialang.org/t/how-to-directly-specify-datatype-when-reading-from-excel-matrix-any-to-vector-int64/88853 "2022-10-18T21:51:45Z")

</div>

I’d like to have some coulmns of an excel sheet in Julia in a Vector{Int64} format. However, it gives me Matrix{Any}. My try: xf = XLSX.readxlsx(\`"C:/Data/sales.xlsx"\`) A = xf\["sheet1!A2:A100"\]) A\_vec = vec(A) …

[Previous page](https://discourse.julialang.org/tag/type/116.md?match_all_tags=true&page=3&tags%5B%5D=type)

[Next page](https://discourse.julialang.org/tag/type/116.md?match_all_tags=true&page=5&tags%5B%5D=type)
