# Type of type parameters

**URL:** https://discourse.julialang.org/t/type-of-type-parameters/5646
**Category:** General Usage
**Created:** [August 30, 2017, 10:08pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646 "2017-08-30T22:08:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)
#### Post date: [August 30, 2017, 10:08pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/1 "2017-08-30T22:08:43Z")

</div>

Sometimes I wish I could express that the parameters of a certain parametrised struct must be of a certain type. For example, I would like to have syntax that allows

```julia
struct ContinuousShift{s::Real} <: AbstractSymmetry end

```

to mean that the parameter `s` will be a real number, or maybe

```julia
struct DiscreteShift{m::Int} <: AbstractSymmetry end

```

for when only integers would make sense. I can live without this, but I think other people might have wanted this kind of ability at some point.

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [August 30, 2017, 10:21pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/2 "2017-08-30T22:21:23Z")

</div>

Is this: `struct ContinuousShift{s<:Real} <: AbstractSymmetry end` not what you want?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [August 30, 2017, 10:28pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/3 "2017-08-30T22:28:56Z")

</div>

I agree that that syntax would be nice. The closest I’ve found is:

```julia
julia> struct Foo{N}
         x::Int
         Foo{N}(x) where {N} = new{typeassert(N, Integer)}(x)
       end

julia> Foo{3}(1)
Foo{3}(1)

julia> Foo{3.5}(1)
ERROR: TypeError: Type: in typeassert, expected Integer, got Float64
Stacktrace:
 [1] Foo{3.5}(::Int64) at ./REPL[1]:3

```

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [August 30, 2017, 10:29pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/4 "2017-08-30T22:29:38Z")

</div>

He wants `s` to be an instance of `Real`, not a subtype of `Real`. It’s not currently supported. See e.g. [https://github.com/JuliaLang/julia/issues/9580#issuecomment-101408507](https://github.com/JuliaLang/julia/issues/9580#issuecomment-101408507).

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [August 30, 2017, 10:37pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/5 "2017-08-30T22:37:16Z")

</div>

FWIW, I think if this were to be implemented, I think

```julia
struct DiscreteShift{m isa Int} <: AbstractSymmetry end

```

would be more consistent than

```julia
struct DiscreteShift{m::Int} <: AbstractSymmetry end

```

because outside of type definitions `m<:Foo` returns a boolean, whereas `m::Int` is a type assertion, as noted in @yuyichao’s comment, and `m isa Int` would also return a boolean.

---

<div class="post-metadata">

### Author: ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)
#### Post date: [August 30, 2017, 10:39pm UTC](https://discourse.julialang.org/t/type-of-type-parameters/5646/6 "2017-08-30T22:39:44Z")

</div>

> [@tkoolen](#):
>
> struct DiscreteShift{m::Int} \<: AbstractSymmetry end

This syntax would be closer to method definitions, though.
