ExTypeRuntime v0.1.0 T View Source

Minimal runtime support for ExType.

It brings serveral useful typespecs and macros to

Generic Protocol

@spec map(T.p(Enumerable, x), (x -> y)) :: [y] when x: any(), y: any()

Ideally, this should be Enumerable.t(x) instead, but Enumerable.t/1 does not exist. Therefore, use T.p(Enumerable, x) to simulate it.

Intersection Type Support

@type intersection(protocol_1, protocol_2) :: T.&({protocol_1, protocol_2})

Type Assertion

x = 123

# left side is expression, right side is typespec
T.assert(x == integer())

Type Inspection

x = 123

# print the type of `x` when using ex_type
T.inspect x

Link to this section Summary

Functions

Assert type while doing type checking.

Inspect type while doing type checking.

Link to this section Types

Link to this type

p(x, y) View Source
p(x, y) :: any() | x | y

Link to this section Functions

Link to this macro

assert(expr, message \\ "") View Source (macro)

Assert type while doing type checking.

Example

x = 10
T.assert x == integer()

T.assert x :: integer() # cast x as integer when x is like any()
Link to this macro

inspect(expr, opts \\ []) View Source (macro)

Inspect type while doing type checking.

Example

T.inspect {x, y}