# Support for other package without requiring it

**URL:** <https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612>\
**Category:** General Usage\
**Created:** [December 7, 2017, 6:24pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612 "2017-12-07T18:24:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [December 7, 2017, 6:24pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/1 "2017-12-07T18:24:14Z")

</div>

Is there a way to provide support for the types from another package without actually requiring that package? For example, say I wanted to make the following type in my package:

```julia
struct Foo{T<:Real} <: AbstractArray{T,2}
    table::Array{T,2}
    samples::Vector{S} where S
    features::Vector{R} where R
end

```

I’d like users of my package to be able to make a `Foo` from a `DataFrame` if they want to:

```julia
function Foo(df::DataFrame)
    return Foo(
            Matrix(df[:,2:end]),
            names(df[2:end]),
            Vector(df[1]))
end

```

… but I don’t actually need `DataFrame`s for anything else. Is there any way to do this without requiring `DataFrames` as a dependency and having `using DataFrames` in my module file?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [December 7, 2017, 6:29pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/2 "2017-12-07T18:29:36Z")

</div>

[Requires.jl](https://github.com/MikeInnes/Requires.jl) should work, if you’re willing to sub one dependency for another.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [December 7, 2017, 6:44pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/3 "2017-12-07T18:44:35Z")

</div>

You could create a _third_ package for the functionality that involves Foo and DataFrame.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [December 7, 2017, 7:13pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/4 "2017-12-07T19:13:08Z")

</div>

I think this will work, thanks!

For completeness, that means in my example above I’d do:

```julia
using Requires

struct Foo{T<:Real} <: AbstractArray{T,2}
    table::Array{T,2}
    samples::Vector{S} where S
    features::Vector{R} where R
end

@require DataFrames function Foo(df::DataFrame)
    return AbundanceTable(
            Matrix(df[:,2:end]),
            names(df[2:end]),
            Vector(df[1]))
end

```

Is that right? I’ll give it a shot!

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [December 7, 2017, 7:21pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/5 "2017-12-07T19:21:19Z")

</div>

Some [plan for glue modules](https://github.com/JuliaLang/julia/issues/2025#issuecomment-338005473) is described on github. That issue is put on the 1.0 milestone.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [December 8, 2017, 5:06pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/6 "2017-12-08T17:06:03Z")

</div>

> [@kevbonham](#):
>
> samples::Vector{S} where S  
> features::Vector{R} where R

Unrelated question: would it be better to write those as: `Vector{<:Any}`?

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [December 9, 2017, 3:37pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/7 "2017-12-09T15:37:54Z")

</div>

Err… I dunno. Does that work?

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [December 9, 2017, 6:00pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/8 "2017-12-09T18:00:58Z")

</div>

Yep, it was a nice little bit of syntactic sugar (I think @-stevengj added it), very useful in cases where you don’t need to use the type variable.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [February 26, 2018, 7:58pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/9 "2018-02-26T19:58:24Z")

</div>

Is there a way to _declare_ a type without _defining_ it? So I can refer to its name in method definitions, implying that I support this type if someone else defines it. This would allow me to support types defined in other packages without requiring those packages.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 26, 2018, 10:12pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/10 "2018-02-26T22:12:49Z")

</div>

> [@e3c6](#):
>
> Is there a way to declare a type without defining it? So I can refer to its name in method definitions, implying that I support this type if someone else defines it. This would allow me to support types defined in other packages without requiring those packages.

Use an abstract type defined in a Base package. That’s why this architecture is used.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [February 26, 2018, 10:21pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/11 "2018-02-26T22:21:14Z")

</div>

That doesn’t work if the type defined in the other package does not inherit from an abstract in Base (other than Any, but that loses specificity)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 26, 2018, 10:21pm UTC](https://discourse.julialang.org/t/support-for-other-package-without-requiring-it/7612/12 "2018-02-26T22:21:53Z")

</div>

> [@e3c6](#):
>
> That doesn’t work if the type defined in the other package does not inherit from an abstract in Base (other than Any, but that loses specificity)

That is why you require a small Base package as the common dependency.
