# New type definition: Galois field in Julia 1.x

**URL:** <https://discourse.julialang.org/t/new-type-definition-galois-field-in-julia-1-x/17123>\
**Category:** New to Julia\
**Created:** [November 3, 2018, 8:23pm UTC](https://discourse.julialang.org/t/new-type-definition-galois-field-in-julia-1-x/17123 "2018-11-03T20:23:16Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [November 19, 2018, 12:11pm UTC](https://discourse.julialang.org/t/new-type-definition-galois-field-in-julia-1-x/17123/7 "2018-11-19T12:11:23Z")

</div>

This code still have a bugs and I don’t know how to remove it.

```julia
# Type definiton
struct GF{p, T} <: Number where {p, T<:Integer}
    rep::T # Representation: intyger which holds the value of element in GF(p)
    
    function GF{p, T}(x::Integer) where {p, T<:Integer}
        return new(mod(x, p))
    end
end
GF{p}(x::T) where {p, T<:Integer} = GF{p, T}(x)

import Base: convert, inv, one, promote_rule, show, zero

function call(::Type{GF{p}}, x::Integer) where p
    if !isprime(p)
        throw(ArgumentError("p must be prime"))
    end
    return GF{p, typeof(x)}(mod(x, p))
end

convert(::Type{GF{p, T}}, x::Integer) where {p, T} = GF{p}(x)
convert(::Type{GF{p}}, x::Integer) where p = GF{p}(x)
convert(::Type{GF{p, T}}, x::GF{p}) where {p, T} = GF{p, T}(x.rep)
promote_rule(::Type{GF{p, T1}}, ::Type{T2}) where {p, T1, T2<:Integer} = GF{p, promote_type(T1, T2)}

# To be able show and print GF(p)
show(io::IO, x::GF) = show(io, x.rep)

```

Since `isprime` is now not defined in global scope `GF{4}(5)` is valid expression and return `0`, of type `GF{4, Int64}`. I confused, why there is no error of using undefined `!isprime(p)` in conditional statement?

Second question: why `GF{4,5}` works and what this expression mean?

---

_[View the full topic](https://discourse.julialang.org/t/new-type-definition-galois-field-in-julia-1-x/17123)._
