# Writing a convert function with parametric types

**URL:** <https://discourse.julialang.org/t/writing-a-convert-function-with-parametric-types/5992>\
**Category:** General Usage\
**Created:** [September 20, 2017, 5:13am UTC](https://discourse.julialang.org/t/writing-a-convert-function-with-parametric-types/5992 "2017-09-20T05:13:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [September 20, 2017, 5:13am UTC](https://discourse.julialang.org/t/writing-a-convert-function-with-parametric-types/5992/1 "2017-09-20T05:13:52Z")

</div>

I’m trying to write a custom convert for FixedPointNumber and finding that I’m still on a learning curve.

The goal is to be able to write

```julia
convert(Fixed{Int16,12}, Fixed{Int16, 10}(0.2231))

```

And have it do the conversion.  
I tried borrowing something from the normed library,

```julia
convert(::Type{Fixed{T1,f}}, x::Fixed{T1,f}) where {T1 <: Signed,f} = Fixed{T1,f1}(convert(T1, x.i), 0)

```

And then realized that ,after trying it, that it won’t work because it’s got the same type for x and the type argument.  
No problem I’ll just make the fractional identifier for each type for each unique and everything will be fine:

```julia
convert(::Type{Fixed{T1,f1}}, x::Fixed{T1,f2}) where {T1 <: Signed,f1} = Fixed{T1,f1}(convert(T1, x.i), 0)

```

I’ve maintained T1 to be the same for the conversion type and the argument because I don’t want to deal with converting Fixed{Int16,10} to Fixed{Int32,10} yet…

but then I get

```julia
ERROR: LoadError: LoadError: UndefVarError: f2 not defined

```

oops. At this point I’ve realized that I don’t actually know what I’m doing and I’m just guessing.  
Could someone explain what’s actually going on in that statement ?

---

<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 20, 2017, 6:22am UTC](https://discourse.julialang.org/t/writing-a-convert-function-with-parametric-types/5992/2 "2017-09-20T06:22:49Z")

</div>

An `f2` type variable seems to be missing from the `where` clause.
