chrisvoncsefalvay / learn-julia-the-hard-way

Learn Julia the hard way!
https://app.gitbook.com/@chrisvoncsefalvay/s/learn-julia-the-hard-way/
Other
772 stars 153 forks source link

Types / why use this constructor as an example? #19

Closed sbromberger closed 9 years ago

sbromberger commented 9 years ago

julia> addition(1+1) ERROR:additionhas no method matching addition(::Int64)

I think a better example would be addition(1, 1) since it's not clear what point you're trying to make: that the number of arguments is not matched, or the type is not matched.

However, later on we have

In the same way, you can assign new values to it. However, these values have to comply with the type's definition in that they have to be convertible to the type specified (in our case, Float64). So, for instance, an Int64 input would be acceptable, since you can convert an Int64 into a Float64 easily. On the other hand, an ASCIIString would not do, since you cannot convert it into an Int64.

And, of course, home = GeoCoordinates(1,1) works, but there's no detail explaining WHY this works as a constructor but it doesn't work for function arguments. (I admit I'm confused by this as well.)