# Structs defined with different fields based on concrete parameters?

**URL:** https://discourse.julialang.org/t/structs-defined-with-different-fields-based-on-concrete-parameters/97772
**Category:** General Usage
**Tags:** question, structtypes
**Created:** [April 22, 2023, 4:18am UTC](https://discourse.julialang.org/t/structs-defined-with-different-fields-based-on-concrete-parameters/97772 "2023-04-22T04:18:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nharr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nharr/32/24698_2.png) [@nharr](https://discourse.julialang.org/u/nharr)
#### Post date: [April 22, 2023, 4:18am UTC](https://discourse.julialang.org/t/structs-defined-with-different-fields-based-on-concrete-parameters/97772/1 "2023-04-22T04:18:23Z")

</div>

Is it possible to define two different structs with the same name but different concrete parameters? I have a single type that changes and I want the rest of my code to react to that, including how other types are structured (and thus how they process the first type).

Example:

```julia
const A = ... # alias to some built-in data structure
const B = ... # alias to some built-in data structure

struct MyType{A}
    a
    b
end

struct MyType{B}
    a
    b
    c
end

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [April 22, 2023, 4:37am UTC](https://discourse.julialang.org/t/structs-defined-with-different-fields-based-on-concrete-parameters/97772/2 "2023-04-22T04:37:36Z")

</div>

No. Julias’ type system is nominal, which means that one name is one type - you cannot have two types with the same name in the same namespace. The canonical way to achieve this is to have one type, with the optional field being typed something like `Union{Nothing T}`, and subsequently checking which case you are in.

---

<div class="post-metadata">

### Author: ![nharr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nharr/32/24698_2.png) [@nharr](https://discourse.julialang.org/u/nharr)
#### Post date: [April 22, 2023, 4:45am UTC](https://discourse.julialang.org/t/structs-defined-with-different-fields-based-on-concrete-parameters/97772/3 "2023-04-22T04:45:48Z")

</div>

Ah, thanks for the explanation.
