Talk:Introducing Julia/Types

This is a nice discussion -- I like the  type example. However, it is incorrect to put  in the definitions of the functions acting on the LSD types. This makes  a parameter in the definition, so you are actually defining the   operation acting on two objects of any type, not just the  type.

Just remove  from the function definitions and it will work, defining the operations only for LSD.

I will try to make this change, but am not very used to the Wiki interface...

[By the way, how do you do code formatting without writing "code" all the time between greater than and less than signs? I am looking for the equivalent of "`" in Markdown.] Dpsanders (discuss • contribs) 16:55, 17 March 2015 (UTC)


 * yes, wikibooks is a bit clunky in places, and currently there's no Geshi highlighting either. I think you can use a single space indent to switch to Pre formatted. Your Julian wisdom and advice is greatly appreciated by this learner... I had originally thought that this project would be superseded by "Learn Julia the Hard Way" on GitHub, but that has started to languish. Cormullion (discuss • contribs) 21:13, 17 March 2015 (UTC)

In the multiplication by a number, you probably want, not  , since the latter allows, e.g., multiplying by a complex number, whereas we want a real number. Currently negative numbers are also allowed; an error could be thrown if the number is negative, e.g.

function *(a::LSD, b::Real) if b < 0 error("Cannot multiply by a negative number") end

totalpence = b * (a.pence + a.shillings * 12 + a.pounds * 240) (pounds, balance) = divrem(totalpence, 240) (shillings, pence) = divrem(balance, 12) LSD(pounds, shillings, pence)p end Dpsanders (discuss • contribs) 21:01, 17 March 2015 (UTC)


 * good idea, I've added that. Cormullion (discuss • contribs) 07:17, 18 March 2015 (UTC)

type examples not working (Julia 0.5.2 on Win7)
The examples are not working for me at the REPL (Julia 0.5.2 on Win7)

julia> abstract type MyAbstractType end

ERROR: syntax: invalid type signature

--141.5.17.106 (discuss) 14:46, 29 May 2017 (UTC)


 * Wikibooks is now aiming for Julia v0.6. Cormullion (discuss • contribs) 18:49, 29 May 2017 (UTC)

Type stability section I think needs some revise
Generally, the author is right, but provided samples does not work the same in latest Julia version.

(v1.0) julia> @time t1(10000000) 0.111979 seconds (29.85 k allocations: 1.588 MiB) 0 (v1.0) julia> @time t1(10000000) 0.101285 seconds (4 allocations: 160 bytes) 0 (v1.0) julia> @time t2(10000000) 0.082770 seconds (24.33 k allocations: 1.292 MiB) 0 (v1.0) julia> @time t2(10000000) 0.072073 seconds (4 allocations: 160 bytes) 0

Note: when we run the same expression, Julia seems to be using some cashed memory and do not do allocations again.

Moreover time difference is not that big now.

Subtypes in 1.0
In version 1.0 the subtype of Integer is different. The BigInt is a subtype of Signed and not listed in , Also the return type is MadCowpoke (discuss • contribs) 00:29, 10 September 2018 (UTC)