# Parametric inner constructor with \`where {T}\` of non-parametric type

**URL:** https://discourse.julialang.org/t/parametric-inner-constructor-with-where-t-of-non-parametric-type/3353
**Category:** General Usage
**Created:** [April 24, 2017, 2:18am UTC](https://discourse.julialang.org/t/parametric-inner-constructor-with-where-t-of-non-parametric-type/3353 "2017-04-24T02:18:41Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [April 24, 2017, 2:18am UTC](https://discourse.julialang.org/t/parametric-inner-constructor-with-where-t-of-non-parametric-type/3353/1 "2017-04-24T02:18:41Z")

</div>

Consider the following type definition attempt, which tries to define a type that stores arrays of x- and y-locations of points:

```julia
julia> struct PointVector{T<:Real}
           x::Vector{T}
           y::Vector{T}
           PointVector{T<:Real}(x, y) = new(x, y)
       end

WARNING: deprecated syntax "inner constructor PointVector(...) around REPL[0]:4".
Use "PointVector{T}(...) where T" instead.
ERROR: syntax: function static parameter names not unique

```

We realize that in defining the inner constructor, the old syntax (without `where`) does not work.

This is fine, because I like the new syntax with `where` and it works:

```julia
julia> struct PointVector{T<:Real}
           x::Vector{T}
           y::Vector{T}
           PointVector{T}(x, y) where {T<:Real} = new(x, y)
       end

julia> PointVector{Int64}([1,0], [0,1])
PointVector{Int64}([1, 0], [0, 1])

```

Now, consider another example that attempts to define `PointVectorFloat64`, a version of `PointVector` that stores `x` and `y` only in `Vector{Float64}` type:

```julia
julia> struct PointVectorFloat64
           x::Vector{Float64}
           y::Vector{Float64}
           PointVectorFloat64(x::Vector{T}, y::Vector{T}) where {T<:Real} = new(float.(x), float.(y))
       end
ERROR: TypeError: Type{...} expression: expected UnionAll, got Type{PointVectorFloat64}

```

The type definition intends to define an inner constructor that is callable only for vectors `x` and `y` with real entries. However, as can be seen in the above example, the new syntax with `where` does not work in defining the inner constructor.

On the other hand, the old syntax without `where` still works:

```julia
julia> struct PointVectorFloat64
           x::Vector{Float64}
           y::Vector{Float64}
           PointVectorFloat64{T<:Real}(x::Vector{T}, y::Vector{T}) = new(float.(x), float.(y))
       end

julia> PointVectorFloat64([1.0, 0.0], [0.0, 1.0])
PointVectorFloat64([1.0, 0.0], [0.0, 1.0])

```

To summarize, it seems that a parametric inner constructor for a non-parametric type cannot be defined using the new syntax with `where`. Is there a way to define such an inner constructor using the new syntax?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [April 24, 2017, 2:59am UTC](https://discourse.julialang.org/t/parametric-inner-constructor-with-where-t-of-non-parametric-type/3353/2 "2017-04-24T02:59:20Z")

</div>

> [@wsshin](#):
>
> PointVector{T\<:Real}(x, y) = new(x, y)

This should not work on 0.5 either. You are defining an inner parameter with an unused type parameter.

```julia
julia> immutable P{T}
           P{T}() = new()
       end
WARNING: static parameter T does not occur in signature for Type at REPL[1]:2.
The method will not be callable.

```

> [@wsshin](#):
>
> ERROR: TypeError: Type{…} expression: expected UnionAll, got Type{PointVectorFloat64}

Seems like a bug.

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [April 24, 2017, 3:05am UTC](https://discourse.julialang.org/t/parametric-inner-constructor-with-where-t-of-non-parametric-type/3353/3 "2017-04-24T03:05:13Z")

</div>

Thanks for the clarification! Will issue a bug report.
