# Type-level variables, i.e. static parameters?

**URL:** https://discourse.julialang.org/t/type-level-variables-i-e-static-parameters/5893
**Category:** General Usage
**Tags:** question
**Created:** [September 14, 2017, 8:39pm UTC](https://discourse.julialang.org/t/type-level-variables-i-e-static-parameters/5893 "2017-09-14T20:39:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)
#### Post date: [September 14, 2017, 8:39pm UTC](https://discourse.julialang.org/t/type-level-variables-i-e-static-parameters/5893/1 "2017-09-14T20:39:06Z")

</div>

I’m writing a parser that has to keep track of many different open files so I have a `File` type that contains all the relevant information inside of it. Is there any way to do this on instantiation? Say something like this

```julia
mutable struct File
    # per-file variables
    offset::Int
    datas
 
    files = Array{File}()

    function File(filename)
        file = new() # open new file and set relevant variables
        push!(files, file)
    end
end

```

Then I could do something like `File.files` or equivalent. This is essentially Type-level fields that behave similarly to `private static` fields in C++

---

<div class="post-metadata">

### Author: ![tlnagy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlnagy/32/5815_2.png) [@tlnagy](https://discourse.julialang.org/u/tlnagy)
#### Post date: [September 14, 2017, 8:50pm UTC](https://discourse.julialang.org/t/type-level-variables-i-e-static-parameters/5893/2 "2017-09-14T20:50:41Z")

</div>

The following seems to accomplish what I want (inspired by [https://github.com/JuliaLang/julia/issues/20353](https://github.com/JuliaLang/julia/issues/20353))

```julia
let
    const files = Dict{String, File}()
    global function add_file(f::File)
        files[f.filepath] = f
    end
    global function get_file_map()
        files
    end
end

```

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 15, 2017, 6:30am UTC](https://discourse.julialang.org/t/type-level-variables-i-e-static-parameters/5893/3 "2017-09-15T06:30:31Z")

</div>

What you have above seems to be the best solution if you want something close to C++'s protections.

Alternatively, you can wrap everything in a module, and just not export `files`. This may make development and debugging easier, but then the variable is modifiable by other functions — you just have to be careful not to do it.
