Skip to content

Commit

Permalink
adjust to [model]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Brown committed Sep 20, 2023
1 parent daec705 commit 7f02e4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/stdlib/models/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
compose(f::Vector{Int}, g::Vector{Int}) = g[f]

dom(f::Vector{Int}) = length(f)
codom(::Vector{Int}; context) = context[:c]
codom(::Vector{Int}; context) = context[:codom]
end

end
16 changes: 9 additions & 7 deletions src/stdlib/models/Op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ rename(nt::NamedTuple, d::Dict{Symbol,Symbol}) =
NamedTuple(get(d, k, k) => v for (k, v) in pairs(nt))


@instance ThCategory{ObT, HomT} (;model::OpC{ObT, HomT, C}) where {ObT, HomT, C} begin
Ob(x::ObT) = Ob(x; model=model.cat)
Hom(x::HomT, d::ObT, cd::ObT) = Hom(x, cd, d; model=model.cat)
id(x::ObT) = id(x; model=model.cat)
dom(f::HomT; context) = codom(f; model=model.cat, context)
codom(f::HomT; context) = dom(f; model=model.cat, context)
@instance ThCategory{ObT, HomT} [model::OpC{ObT, HomT, C}] where {ObT, HomT, C} begin
Ob(x::ObT) = Ob[model.cat](x)
Hom(x::HomT, d::ObT, cd::ObT) = Hom[model.cat](x, cd, d)
id(x::ObT) = id[model.cat](x)
dom(f::HomT; context) =
codom[model.cat](f; context=rename(context, Dict(:dom=>:codom, :codom=>:dom)))
codom(f::HomT; context) =
dom[model.cat](f; context=rename(context, Dict(:dom=>:codom, :codom=>:dom)))
compose(f::HomT, g::HomT; context=nothing) =
compose(g, f; model=model.cat,
compose[model.cat](g, f;
context=rename(context, Dict(:a=>:c, :c=>:a, :b=>:b)))
end

Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/models/Op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using .ThCategory
@test compose([1,1,1,3,2], [5]) == [2]
@test compose([1,1,1,3,2], [5]; context=(;)) == [2]
@test codom([5]) == 1
@test dom([5]; context=(c=10,)) == 10
@test dom([5]; context=(dom=10,)) == 10
end

end # module

0 comments on commit 7f02e4a

Please sign in to comment.