# Question about abstract type interfaces

**URL:** https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605
**Category:** New to Julia
**Created:** [April 29, 2018, 1:17pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605 "2018-04-29T13:17:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [April 29, 2018, 1:17pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/1 "2018-04-29T13:17:15Z")

</div>

Hi all, yet another newbie questions…  
I want to create a new type as a subtype of an existing abstract type:  
TinyBandedMatrix{T} \<: AbstractSparseMatrix{T}  
I wonder how to find details about the AbstractSparseMatrix interface that my new type must fullfill…

---

<div class="post-metadata">

### Author: ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)
#### Post date: [April 29, 2018, 2:26pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/2 "2018-04-29T14:26:33Z")

</div>

Since AbstractSparseMatrix is a AbstractArray, start here:  
[https://docs.julialang.org/en/stable/manual/interfaces/#man-interface-array-1](https://docs.julialang.org/en/stable/manual/interfaces/#man-interface-array-1)

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [April 29, 2018, 3:00pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/3 "2018-04-29T15:00:57Z")

</div>

Thank you !  
I guess I should start by `AbstractArray` and then figure out what additional functions should be available for `AbstractSparseMatrix`.  
Sorry for this newbie question but the interface documentation should not be available for each abstract type ?  
To me an abstract type may require an interface specification corresponding more or less to a concept in C++, traits in Rust or Haskell typeclass… Obviously I am still stuck in my OO way of thinking.

---

<div class="post-metadata">

### Author: ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)
#### Post date: [April 29, 2018, 3:45pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/4 "2018-04-29T15:45:22Z")

</div>

The documentation of interfaces has been improved a lot lately, but obviously more would still be better.

I’m not sure that sub-types always add to an interface. In this case a SparseMatrix is just a Matrix. Only the way things are stored in memory is different.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [April 30, 2018, 8:18am UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/5 "2018-04-30T08:18:12Z")

</div>

Thank you. It is not clear to me that SparseMatrix is just a Matrix. I can imagine generic algorithms (e.g. matrix-vector product, show methods, solver like Gauss-Seidel) that may be common to different implementations (and different storage strategies) of sparse matrices. If someone develop a nice HTML show method for sparse matrices, it will probably be based on a common interface enabling iteration over non zero elts…

---

<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: [April 30, 2018, 10:39am UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/6 "2018-04-30T10:39:48Z")

</div>

Implementation and user API are precisely what Julia allows you to separate. Ideally, a sparse matrix is “just a matrix” in 90% of the cases from the user’s point of view, in the sense that knowing that it implements the interface is enough (for the remaining 10%, the user needs to care, eg choose to create such a matrix, etc).

At the same time, the developer would implement the right algorithm where it makes sense. The type hierarchy is a related design decision, and depends on how generic the relevant algorithms are. With careful design, only some functions need to be implemented for very specific subtypes, which can then be used by more general types, etc. Besides `LinearAlgebra`, the code related to `<: AbstractRange` is a nice example of this in `Base`.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [April 30, 2018, 1:15pm UTC](https://discourse.julialang.org/t/question-about-abstract-type-interfaces/10605/7 "2018-04-30T13:15:36Z")

</div>

Totally OK. Using a matrix requires to know its interface. The same applies for someone who want to write a concrete type being a subtype of an `AbstractSparseMatrix`. Otherwise, why bother writing a nice documentation for `AbstractArrays` or `AbstractRange` ?
