-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.jl
24 lines (17 loc) · 851 Bytes
/
types.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
abstract type AbstractType end
struct →{A, B} <: AbstractType where {A <: AbstractType, B <: AbstractType}
name::Union{Symbol, Expr}
end
→(::Type{A}, ::Type{B}) where {A <: AbstractType, B <: AbstractType} = →{A, B}
Base.show(io::IO, ::Type{→{A, B}}) where {A <: AbstractType, B <: AbstractType} = print(io, "$A → $B")
Base.show(io::IO, x::AbstractType) = print(io, "$(x.name) : $(typeof(x))")
dom(::Type{→{A, B}}) where {A <: AbstractType, B <: AbstractType} = A
cod(::Type{→{A, B}}) where {A <: AbstractType, B <: AbstractType} = B
var(x::Symbol, ::Type{T}) where {T <: AbstractType} = Expr(:(=), x, T(x)) |> eval
macro var(x, T) var(x, eval(T)) end
macro type(T)
:(struct $T <: AbstractType
name::Union{Symbol, Expr}
end)
end
(f::(→{A, B}))(a::A) where {A, B <: AbstractType} = B(:($(f.name)($(a.name))))