AaltoRSE / julia-introduction

Two-day introduction course to Julia programming language
MIT License
9 stars 7 forks source link

02_Julia notebook #14

Open tpfau opened 2 years ago

tpfau commented 2 years ago

In the last section (Advanced: Dynamic types) if you run the code you get an exception. IS that intentional and for the students to figure out, or should this be corrected?

lucaferranti commented 2 years ago

I think the sentence

You can force the type using the :: syntax (read is instance of.)

is quite incorrect in that context. The :: operator, when used after an expression, is used to hint what the expected type is and throw an error if the returned type does not match the expected type.

For the example

a = 1
b = 3
(a/b)::Int

The / operator always returns a float when called with integer parameters (otherwise you would have type instability) and hence you get an error since a float cannot be an integer

lucaferranti commented 2 years ago

see the julia documentation: https://docs.julialang.org/en/v1/manual/types/#Type-Declarations

rantahar commented 2 years ago

Is it better now, @lucaferranti?