# Primitive parametric types

**URL:** <https://discourse.julialang.org/t/primitive-parametric-types/27173>\
**Category:** General Usage\
**Tags:** parametric-types\
**Created:** [August 5, 2019, 11:14am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173 "2019-08-05T11:14:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [August 5, 2019, 11:14am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/1 "2019-08-05T11:14:59Z")

</div>

Is it possible to specify the bit size of a primitive type as a parameter?  
If I try:

```julia
primitive type MyType{B,T,D} <: Number B end

```

I get :

```julia
ERROR: invalid declaration of primitive type MyType

```

additionally, I would like to use the parameters `T` and `D` as a type and a constant respectively in methods that take `MyType{B,T,D}` as one of their arguments

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [August 5, 2019, 11:50am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/2 "2019-08-05T11:50:26Z")

</div>

No. And you wouldn’t really want to do that. You can have a primitive type that has a parameter; you cannot use the parameter to provide part of the primitive type’s specific definition. The parameter cannot be swallowed into the declaration of the type itself.

---

<div class="post-metadata">

**Author:** ![hros](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hros](https://discourse.julialang.org/u/hros)\
**Post date:** [August 6, 2019, 8:51am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/3 "2019-08-06T08:51:32Z")

</div>

> [@JeffreySarnoff](#):
>
> you wouldn’t really want to do that

Actually, that is exactly what I wanted to do 🙂  
I don’t understand the problems involved with this.

If I could simplify the question. How about the following:

```julia-REPL
julia> primitive type MyType{T} <: Number sizeof(T)*8 end

julia> sizeof(MyType{UInt32})
24

julia> sizeof(UInt32)
4

```

This syntax does compile, however as you can see the number of bits is 24\*8, and this is the same whatever `T` is.  
Is there any way to declare primitive parametric types with varying sizes?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [August 6, 2019, 9:08am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/4 "2019-08-06T09:08:34Z")

</div>

There is not because primitive types are used to generate the system level number types and if one could declare a primitive type, say `Float64`, with varying size … well that would lead to the possibility of Float64s with the precision of Float16s. (OK, I may be overstating this … essentially, though you should not conceptualize primitive types (parameterized or not) as if they were another sort of possibly parameterized struct.)

Two different phyla [if you happen to be a Bio person].

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [August 6, 2019, 9:10am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/5 "2019-08-06T09:10:15Z")

</div>

What is it that you intend to do with this – there may be a much better approach that gives the outcome you seek. Pretend you had that sort of type – how are you applying it and why – to what end?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [August 6, 2019, 9:12am UTC](https://discourse.julialang.org/t/primitive-parametric-types/27173/6 "2019-08-06T09:12:23Z")

</div>

@hros let me know … we’ll keep moving this forward.

you might use a parameterized struct and this package  
[https://github.com/vtjnash/ComputedFieldTypes.jl](https://github.com/vtjnash/ComputedFieldTypes.jl)  
(it does nothing with primitive types, but your struct field can be of a computed type).
