# Is there an efficient way to associate a value with a parameterized type.For exa

**URL:** https://discourse.julialang.org/t/is-there-an-efficient-way-to-associate-a-value-with-a-parameterized-type-for-exa/54940
**Category:** General Usage
**Created:** [February 9, 2021, 4:16pm UTC](https://discourse.julialang.org/t/is-there-an-efficient-way-to-associate-a-value-with-a-parameterized-type-for-exa/54940 "2021-02-09T16:16:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [February 9, 2021, 4:16pm UTC](https://discourse.julialang.org/t/is-there-an-efficient-way-to-associate-a-value-with-a-parameterized-type-for-exa/54940/1 "2021-02-09T16:16:23Z")

</div>

Is there an efficient way to associate a value with a parameterized type.  
For example:  
`struct GaloisField{p,r}; val::Int end`

```julia
+(a::G, b::G} where G&lt;:GaloisField = addop(a.val, b.val, logtable(G))

```

Memoization of `logtable` or using a global dictionary is not fast enough.

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1612886961370800?thread_ts=1612886961.370800&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)
#### Post date: [February 10, 2021, 5:49pm UTC](https://discourse.julialang.org/t/is-there-an-efficient-way-to-associate-a-value-with-a-parameterized-type-for-exa/54940/2 "2021-02-10T17:49:14Z")

</div>

The following post of @benoitrichard gave the solution:  
I think what you need is a generated function then

@generated function logtable(::Type{G}) where {p, r, G \<: GaloisField{p, r}}  
lg = \_logtable(p, r) # The actual computation  
return :($lg)  
end

That way the actual logtable will be comptued only once per type
