Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2026-01-17 19:32:38
Size: 1522
Comment: Initial commit
Revision 4 as of 2026-01-18 23:01:45
Size: 2416
Comment: More notes
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Julia is a dynamically typed language. Values have a concrete type. While Julia is a dynamically typed language, values have a concrete type.
Line 6: Line 6:

----



== Type Hints ==

To provide the interpreter/compiler a type hint, try:

{{{
julia> (1+2)::Int
}}}

This acts as a type assertion: if the annotated value is not that type, then a type error is thrown.
Line 38: Line 24:
 * `AbstractArray`
   * `AbstractVector`
   * `AbstractMatrix`
   * `AbstractRange`
Line 73: Line 63:
----



== Composite Types ==

Structs are a composite data type. Struct values can be instantiated like:

{{{
julia> struct Foo
           bar
           baz
           qux
       end

julia> foo = Foo("Hello, world.", 23, 1.5)
Foo("Hello, world.", 23, 1.5)
}}}

Fields are accessed by the dot operator.

{{{
julia> foo.bar
"Hello, world."
}}}

By default, struct objects are immutable.

----



== Collection Types ==

Values can be collected in a variety of series types.

The `Array` type is a general purpose series of values, all of the same type. Both [[Julia/Vectors|Vector]] and [[Julia/Matrices|Matrix]] types descend from `AbstractArray`.

The range operator (`:`) creates collections that have some type descending from `AbstractRange`, which also descends from `AbstractArray`. The differences between e.g. `UnitRange` and `OrdinalRange` relate to the available optimizations.

----



== Nothing Type ===

The singleton constant `nothing` is of type `Nothing`.

Julia Data Types

While Julia is a dynamically typed language, values have a concrete type.


Abstract Types

Abstract types should not be used directly. They are supertypes that categorize behaviors. They are however useful for constructing a novel data type, or for typing the arguments to a function.

The primary set of abstract types, with their hierarchy of supertypes and subtypes indicated by indentation, is:

  • Number

    • Real

      • AbstractFloat

      • Integer

        • Signed

        • Unsigned

  • AbstractChar

  • AbstractString

  • AbstractArray

    • AbstractVector

    • AbstractMatrix

    • AbstractRange


Numeric Types

The set of primitive types that descend from the Number abstract type are:

  • Bool

  • Int8

  • Int16

  • Int32

  • Int64

  • Int128

  • UInt8

  • UInt16

  • UInt32

  • UInt64

  • UInt128

  • Float16

  • Float32

  • Float64


String Types

String is a subtype of AbstractString that implicitly is encoded in UTF-8.

Packages may create novel subtypes of AbstractString, so consider typing string arguments for functions as AbstractString rather than String.

Char is a subtype of AbstractChar, and is a 32-bit representation a Unicode character.


Composite Types

Structs are a composite data type. Struct values can be instantiated like:

julia> struct Foo
           bar
           baz
           qux
       end

julia> foo = Foo("Hello, world.", 23, 1.5)
Foo("Hello, world.", 23, 1.5)

Fields are accessed by the dot operator.

julia> foo.bar
"Hello, world."

By default, struct objects are immutable.


Collection Types

Values can be collected in a variety of series types.

The Array type is a general purpose series of values, all of the same type. Both Vector and Matrix types descend from AbstractArray.

The range operator (:) creates collections that have some type descending from AbstractRange, which also descends from AbstractArray. The differences between e.g. UnitRange and OrdinalRange relate to the available optimizations.


== Nothing Type ===

The singleton constant nothing is of type Nothing.


CategoryRicottone

Julia/DataTypes (last edited 2026-01-18 23:01:45 by DominicRicottone)