# Declaring types from packages

**URL:** https://discourse.julialang.org/t/declaring-types-from-packages/37737
**Category:** General Usage
**Tags:** package, parametric-types
**Created:** [April 17, 2020, 5:12am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737 "2020-04-17T05:12:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![amejia83](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amejia83](https://discourse.julialang.org/u/amejia83)
#### Post date: [April 17, 2020, 5:12am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/1 "2020-04-17T05:12:58Z")

</div>

Hello, I am facing an issue that I’m sure is very minor, but I cannot find anything in the documentation for either the package or Julia documentation. I’m hoping that someone here can help me out (without knowing too much about abstractalgebra.jl)

My main question is that I want to create a new “compound” struct from that assembles two types from the package AbstractAlgebra.jl. Consider the following

```julia
using AbstractAlgebra
FreeModule=AbstractAlgebra.Generic.FreeModule
Morphism=AbstractAlgebra.Generic.ModuleHomomorphism
mutable struct ChainComplex
    modules::Array{FreeModule}
    morphisms::Array{Morphism}
end

```

Now, apriori, the types FreeModule are already parametric. Indeed they take as input types such as BigInt, float{64} etc. I wanted to somehow include this in my definition, such as

```julia
FreeModule=AbstractAlgebra.Generic.FreeModule{T}
Morphism=AbstractAlgebra.Generic.ModuleHomomorphism{T}

```

but this appears to be nonsense in Julia, so I’m wondering how I can define this new compound type. When I try the first option above, and try to construct it, I get the error

```julia
M_1 = FreeModule(ZZ, 2)
M_2=FreeModule(ZZ,2)
f = ModuleHomomorphism(M_1, M_2, matrix(ZZ, 2, 2, [1, 2, 3, 4]))
ChainComplex([M_1,M_2],[f])

```

> MethodError: Cannot `convert` an object of type  
> AbstractAlgebra.Generic.ModuleHomomorphism{BigInt} to an object of type  
> Array{AbstractAlgebra.Generic.ModuleHomomorphism,N} where N

which is a little bit jibberish, but I take it to mean that I declared this to be of a particular type without specifying BigInt, so once that specification comes in, it breaks my type.

If it is helpful, here is the return from the function typeof(M\_1) and typeof(f) respectively:

`AbstractAlgebra.Generic.FreeModule{BigInt}`  
`AbstractAlgebra.Generic.ModuleHomomorphism{BigInt}`

Is there any simple way to get the functionality that I want?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [April 17, 2020, 5:25am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/2 "2020-04-17T05:25:38Z")

</div>

What you want is

```julia
mutable struct ChainComplex{F<:FreeModule,M<:ModuleHomorphism}
    modules::Array{F}
    morphisms::Array{M}
end

```

This makes your `ChainComplex` parametrized on the type of your module and morphism. It’s in the docs here [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/index.html#Parametric-Abstract-Types-1)

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [April 17, 2020, 5:37am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/4 "2020-04-17T05:37:11Z")

</div>

From the error message, it looks like you pass in the second argument directly, without wrapping it into an array. But looking at your example code in the first post, you actually have `[f]`, so maybe it’s just some copy-n-paste error?

---

<div class="post-metadata">

### Author: ![amejia83](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amejia83](https://discourse.julialang.org/u/amejia83)
#### Post date: [April 17, 2020, 5:39am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/5 "2020-04-17T05:39:53Z")

</div>

ugh, sorry I grabbed the wrong error message. My apologies. I’ve edited the comment to include the correct one.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [April 17, 2020, 5:52am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/7 "2020-04-17T05:52:49Z")

</div>

That doesn’t look like an error, just a really long type.

---

<div class="post-metadata">

### Author: ![amejia83](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@amejia83](https://discourse.julialang.org/u/amejia83)
#### Post date: [April 17, 2020, 5:55am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/8 "2020-04-17T05:55:47Z")

</div>

_facepalm_ issue resolved. Thank you so much to all who assisted me in this very beginner problem. This seems like a great community.

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [April 17, 2020, 8:31am UTC](https://discourse.julialang.org/t/declaring-types-from-packages/37737/9 "2020-04-17T08:31:51Z")

</div>

No problem. I was actually recently thinking about how to handle nested parametetric types, that is, parametric types where the type parameters are themselves parametric types. And your example shows that there’s nothing special about that scenario 👍
