# Parametric Type Usage

**URL:** <https://discourse.julialang.org/t/parametric-type-usage/34170>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 4, 2020, 2:55pm UTC](https://discourse.julialang.org/t/parametric-type-usage/34170 "2020-02-04T14:55:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [February 4, 2020, 2:55pm UTC](https://discourse.julialang.org/t/parametric-type-usage/34170/1 "2020-02-04T14:55:41Z")

</div>

Suppose I have a type `PieceWiseAffineFunction` with a number of segments.  
I want to convert (approximate) an instante with _m_ segments into an instant with _n_ segments. (_n\<m_)

```julia
type PieceWiseAffineFunction
    k::Vector{Float64}
    d::Vector{Float64}
end

```

If I have an instant with 3 segments `k` and `d` are 3 long.

```julia
p = PieceWiseAffineFunction([1.0,2.0,3.0], [4.0,5.0,6.0])

```

Is there a way to use parametric types to achieve this e.g.:

```julia
q = PieceWiseAffineFunction{2}(p)

```

or is this bad practice and it I should simply use an outer constructor?

```julia
function PieceWiseAffineFunction(p::T, num_seg::Int) where {T<:PieceWiseAffineFunction}
   # TODO:
end

q = PieceWiseAffineFunction(p, 2)

```

---

<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:** [February 4, 2020, 3:25pm UTC](https://discourse.julialang.org/t/parametric-type-usage/34170/2 "2020-02-04T15:25:06Z")

</div>

> [@ohmsweetohm1](#):
>
> or is this bad practice and it I should simply use an outer constructor?

Yeah, I would agree with both of those statements. Using `{2}` to pass something which is not a type parameter would be pretty surprising and unusual. An outer constructor would be easy to implement and easy to read.
