January 2020
Intermediate to advanced
532 pages
13h 31m
English
As discussed in Chapter 2, Modules, Packages, and Data Type Concepts, we can define functions that take abstract types as arguments. When it comes to dispatch, Julia will find the method that matches the narrowest type in the arguments.
To illustrate this concept, let's return to our favorite example in this chapter regarding spaceships and asteroids! In fact, we will improve our data types as follows:
# A thing is anything that exist in the universe.# Concrete type of Thing should always have the following fields:# 1. position# 2. sizeabstract type Thing end# Functions that are applied for all Thing'sposition(t::Thing) = t.positionsize(t::Thing) = t.sizeshape(t::Thing) = :unknown
Here, we have defined an abstract ...
Read now
Unlock full access