AnonymousTypes
Anonymous mutable and immutable types.
Contents
Installation
This package is unregistered and so must be installed using Pkg.clone
Pkg.clone("https://github.com/MichaelHatherly/AnonymousTypes.jl")
Index
AnonymousTypes
AnonymousTypes.@Anon
AnonymousTypes.@Immutable
AnonymousTypes.@Type
AnonymousTypes.@immutable
AnonymousTypes.@type
Public Interface
#
AnonymousTypes
— Module.
Anonymous types are automatically generated types where the field names and field types are based on the values provided to them.
This package provides syntax for creating instances of these types, as well as syntax for dispatching to different methods based on their structural properties such as mutability, field names, and field types.
The following exported macros are provided for public use.
Type Instantiation:
Type Signatures:
#
AnonymousTypes.@type
— Macro.
Create an anonymous mutable type instance.
Examples
t = @type x = 1 y = 2 t.x + t.y == 3
Variables may be used in place of =
expressions:
x = 1 t = @type x y = 2 t.x + t.y == 3
#
AnonymousTypes.@immutable
— Macro.
Create an anonymous immutable type instance.
See @type
for examples of use since, apart from their names, both macros support the same set of features.
#
AnonymousTypes.@Anon
— Macro.
Create signature for anonymous (either mutable or immutable) types. Can be used in function definitions as follows:
f(a :: @Anon(x, y), b :: @Anon(:: Integer, y :: Vector)) = ...
Syntax
Anonymous type with 2 fields, a
and b
:
@Anon(a, b)
Anonymous type with 3 unnamed fields of type T_i
for i = 1:3
:
@Anon(:: T_1, :: T_2, :: T_3)
Anonymous type with 1 field named a
subtyping from Integer
:
@Anon(a :: Integer)
#
AnonymousTypes.@Type
— Macro.
Similar to @Anon
but limited to mutable types.
#
AnonymousTypes.@Immutable
— Macro.
Similar to @Anon
but limited to immutable types.