# How to declare a type

**URL:** <https://discourse.julialang.org/t/how-to-declare-a-type/28068>\
**Category:** New to Julia\
**Created:** [August 27, 2019, 9:48pm UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068 "2019-08-27T21:48:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Cuervo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_cuervo/32/7403_2.png) [@Santiago\_Cuervo](https://discourse.julialang.org/u/Santiago_Cuervo)\
**Post date:** [August 27, 2019, 9:48pm UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068/1 "2019-08-27T21:48:25Z")

</div>

I want to declare a type that describe a Well.

```julia
mutable struct Well
   Name::String
   Surv::Survey
   Perf::Array{Perf}
   end

```

I want to define if the well is either Injector or producer. How could I define it?

```julia
Injector::Bool

```

I think there is a way by setting a variable a Bool Type. but is there a way of telling Julia `::Producer` or `::Injector`???

What would be the struct of these types?

thank you

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [August 27, 2019, 9:59pm UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068/2 "2019-08-27T21:59:39Z")

</div>

> [@Santiago\_Cuervo](#):
>
> I think there is a way by setting a variable a Bool Type. but is there a way of telling Julia `::Producer` or `::Injector` ???
> 
> What would be the struct of these types?
> 
> thank you

you can use abstract types, maybe:

```julia
abstract type WellType end
struct Injector <: WellType end
struct Producer <: WellType end
mutable struct Well
   Name::String
   Surv::Survey
   Perf::Array{Perf}
   classification::WellType
  end

```

just to understand the context, are we talking about oil wells, right?

---

<div class="post-metadata">

**Author:** ![Santiago\_Cuervo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_cuervo/32/7403_2.png) [@Santiago\_Cuervo](https://discourse.julialang.org/u/Santiago_Cuervo)\
**Post date:** [August 28, 2019, 1:02am UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068/3 "2019-08-28T01:02:40Z")

</div>

> [@longemen3000](#):
>
> abstract type WellType end struct Injector \<: WellType end struct Producer \<: WellType end mutable struct Well Name::String Surv::Survey Perf::Array{Perf} classification::WellType end

Yes they are Oil Wells. with that abstract type how you can introduce a new object?

I tryied but i’m a little confused

```julia
abstract type WellType end
struct Injector <: WellType end
struct Producer <: WellType end
mutable struct Well
   Name::String
   Surv::Int
   Perf::Int
   classification::WellType
  end

Well("Merlin-1",5,7,::Producer)??

```

Thank you

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [August 28, 2019, 1:04am UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068/4 "2019-08-28T01:04:02Z")

</div>

you have to create an instance of the type first:

```julia
Well("Merlin-1",5,7,Producer())

```

as an alternative, you can create a variable holding the type and pass it to the constructor:

```julia
producer = Producer()
Well("Merlin-1",5,7,producer)

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 28, 2019, 1:17am UTC](https://discourse.julialang.org/t/how-to-declare-a-type/28068/5 "2019-08-28T01:17:42Z")

</div>

How about an `@enum`?

```julia
julia> @enum WellType Producer Injector

julia> Producer
Producer::WellType = 0

julia> mutable struct Well; x :: WellType; end

julia> w = Well(Producer)
Well(Producer)

```
