# Struct with Multiple Parametric Types

**URL:** <https://discourse.julialang.org/t/struct-with-multiple-parametric-types/31030>\
**Category:** New to Julia\
**Tags:** parametric-types, struct\
**Created:** [November 13, 2019, 5:06am UTC](https://discourse.julialang.org/t/struct-with-multiple-parametric-types/31030 "2019-11-13T05:06:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric_chen/32/5992_2.png) [@Eric\_Chen](https://discourse.julialang.org/u/Eric_Chen)\
**Post date:** [November 13, 2019, 5:06am UTC](https://discourse.julialang.org/t/struct-with-multiple-parametric-types/31030/1 "2019-11-13T05:06:37Z")

</div>

I have a few “operations” and I will read a CSV file to determine a list of operation to perform.

I also have a collection of operations “ManyOps” that hold multiple operations.

Operate → abstract type  
Cut, Roll, Push → concrete type  
ManyOps → concrete type with Parametric Types of Cut, Roll, Push

I want to avoid using abstract type “Vector{Operate}”, therefore I have to use Tuple of Operate.

But below generate an error, may I know how to fix it?

Ideally, I want to generate a ManyOps{Cut, Roll}, and the Cut and Roll can be variable size, read from a CSV file  
e.g. the CSV file may contain: Cut, Roll, Cut, Roll, Push, Cut

Thank you

> abstract type Operate end
> 
> struct Cut \<: Operate  
> member::String  
> Cut() = Cut(“t”)  
> end
> 
> struct Push \<: Operate  
> member::Int  
> Push() = Push(1)  
> end
> 
> struct Roll \<: Operate  
> member::Symbol  
> Roll() = Roll(:a)  
> end
> 
> struct ManyOps{T}  
> ops::T  
> ManyOps(ops::T) where {T} = new{Union{map(typeof, ops)…}}(ops)  
> end  
> ManyOps(ops::Operate…) = ManyOps(ops)

> ManyOps(Cut(), Roll())

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 13, 2019, 7:47am UTC](https://discourse.julialang.org/t/struct-with-multiple-parametric-types/31030/2 "2019-11-13T07:47:34Z")

</div>

You need to use `new` for the inner constructors of `Cut` and `Roll`.

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [November 13, 2019, 9:27am UTC](https://discourse.julialang.org/t/struct-with-multiple-parametric-types/31030/3 "2019-11-13T09:27:47Z")

</div>

How about wrapping a tuple?

```julia
abstract type Operate end

struct Cut <: Operate
    member::String
end
Cut() = Cut("t")

struct Push <: Operate
    member::Int
end
Push() = Push(1)

struct Roll <: Operate
    member::Symbol
end
Roll() = Roll(:a)

struct ManyOps{T<:Tuple{Vararg{<:Operate}}}
    ops::T
end

# ManyOps( ops...) = ManyOps( ops ) # Don't do this: It calls itself
ManyOps( op1::T ) where T<:Operate = ManyOps( (op1,) )
ManyOps( op1, op2, op3...) = ManyOps( (op1, op2, op3...) )
ManyOps( Cut(), Roll() )
ManyOps( 123, "x" ) # errors

```
