abstract type Term end
abstract type Compound <: Term end
abstract type Statement <: Term end
struct Product <: Compound
comps::Vector{Term}
end
struct Word <: Term
literal::String
end
struct Inheritance <: Statement
t1::Term
t2::Term
end
New types should implement the 2-argument form, typically by calling the 2-argument `hash`
method recursively in order to mix hashes of the contents with each other (and with `h`).
Typically, any type that implements `hash` should also implement its own `==` (hence
`isequal`) to guarantee the property mentioned above. Types supporting subtraction
(operator `-`) should also implement [`widen`](@ref), which is required to hash
values inside heterogeneous arrays.
大致如下:
import Base.hash
function hash(x::Product)
hash(x.comps)
end
function hash(x::Inheritance)
hash(x.t1) ⊻ hash(x.t2)
end
julia> a1 = Inheritance(Product(Term[Word("a"), Word("b")]), Word("b"))
Inheritance(Product(Term[Word("a"), Word("b")]), Word("b"))
julia> a2 = deepcopy(a1)
Inheritance(Product(Term[Word("a"), Word("b")]), Word("b"))
julia> hash(a1)
0xa858c484eaa939fb
julia> hash(a2)
0xa858c484eaa939fb