# Storing non-isbits data in type parameters

**URL:** <https://discourse.julialang.org/t/storing-non-isbits-data-in-type-parameters/112748>\
**Category:** General Usage\
**Created:** [April 10, 2024, 1:15am UTC](https://discourse.julialang.org/t/storing-non-isbits-data-in-type-parameters/112748 "2024-04-10T01:15:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [April 10, 2024, 1:15am UTC](https://discourse.julialang.org/t/storing-non-isbits-data-in-type-parameters/112748/1 "2024-04-10T01:15:50Z")

</div>

This is most likely not a new discovery, but I just realized you can effectively store non-isbits data in type parameters. MWE:

```julia-repl
julia> struct Value{T} end

julia> Value(x) = Value{Symbol(repr(x))}();

julia> unwrap(::Value{sym}) where {sym} = eval(Meta.parse(string(sym)));

julia> v = Value([1, 2])
Value{Symbol("[1, 2]")}()

julia> unwrap(v)
2-element Vector{Int64}:
 1
 2

julia> ValueType(x) = Value{Symbol(repr(x))};

julia> foo(::ValueType([1, 2])) = 42;

julia> foo(v)
42

```

So, if you ever wanted to dispatch on non-isbits values, now you can. Use wisely. 😈

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [April 10, 2024, 2:23am UTC](https://discourse.julialang.org/t/storing-non-isbits-data-in-type-parameters/112748/2 "2024-04-10T02:23:28Z")

</div>

In summary, by converting to a `Symbol` instance, the only non-isbits value allowed as type parameters, in addition to `Tuple`s containing `Symbol`s. Note that this has a freezing effect, making an immutable copy of a mutable instance, which may be more familiar in the context of dictionary keys.

I’m wondering if converting things to `Symbol`s is unsustainable at some point, I don’t know what happens to interned strings in the long run.
