I am trying to create an "integer mod p" in Julia. (I am sure there is already a package for this, this is just a personal exercise.)
type Intp{p} v::Int8 end function add(a::Intp{p},b::Intp{p}) return Intp{p}((av + bv) % p) end
I get an error when defining add that says p is undefined. How to set p link from inside?
(Note: I could do something like
type Intp v::Int8 p end function add(a::Intp,b::Intp) return Intp((av + bv) % ap,p) end
but this requires p to be stored with each number. I feel that it will be ineffective, and I mean generalizations where it will be really ineffective. I would prefer that p is simply indicated once for the type and refers to functions that take things of this type as arguments.)
source share