Skip to content

Commit b467b58

Browse files
committed
A few type definition adjustments; clean up a couple functions
1 parent f4b699d commit b467b58

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/categorical_algebra/FinSets.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ FinSet(n::Int) = FinSetInt(n)
5454

5555
Base.iterate(set::FinSetInt, args...) = iterate(1:set.n, args...)
5656
Base.length(set::FinSetInt) = set.n
57-
Base.in(set::FinSetInt, elem) = in(elem, 1:set.n)
57+
# Code review note: the arguments seem to have been placed backwards originally
58+
Base.in(elem, set::FinSetInt) = in(elem, 1:set.n)
5859

5960
Base.show(io::IO, set::FinSetInt) = print(io, "FinSet($(set.n))")
6061

@@ -285,12 +286,27 @@ Base.collect(f::SetFunction) = force(f).func
285286

286287
""" Function in **FinSet** represented explicitly by a vector.
287288
"""
288-
const FinFunctionVector{S,T,V<:AbstractVector{T}} =
289-
FinDomFunctionVector{T,V,<:FinSet{S,T}}
290-
291-
Base.show(io::IO, f::FinFunctionVector) =
289+
# Code review note: This type declaration is regarded by Julia
290+
# as equal (i.e. ==) to the extant declaration. I feel that giving
291+
# `FinFunctionVector` an explicit parameter to represent the type of the
292+
# codomain improves the self-documentation aspect of the code.
293+
const FinFunctionVector{S,T,V<:AbstractVector{T},Codom<:FinSet{S,T}} =
294+
FinDomFunctionVector{T,V,Codom}
295+
296+
# Code review note: showing just the length of the codomain is not ideal when
297+
# the codomain is not a `FinSetInt`
298+
Base.show(io::IO, f::FinFunctionVector{Int}) =
292299
print(io, "FinFunction($(f.func), $(length(dom(f))), $(length(codom(f))))")
293300

301+
function Base.show(io::IO, f::F) where {F<:FinFunctionVector}
302+
Sets.show_type_constructor(io, F)
303+
print(io, "(")
304+
show(io, f.func)
305+
print(io, ", $(length(dom(f))), ")
306+
Sets.show_domains(io, f, domain=false)
307+
print(io, ")")
308+
end
309+
294310
Sets.do_compose(f::FinFunctionVector, g::FinDomFunctionVector) =
295311
FinDomFunctionVector(g.func[f.func], codom(g))
296312

@@ -542,8 +558,10 @@ force(f::FinDomFunctionDict) = f
542558

543559
""" Function in **FinSet** represented by a dictionary.
544560
"""
545-
const FinFunctionDict{K,D<:AbstractDict{K},Codom<:FinSet} =
561+
const FinFunctionDict{K,D<:AbstractDict{K},S,Codom<:FinSet{S}} =
546562
FinDomFunctionDict{K,D,Codom}
563+
# Code review note: The additional parameter `S` allows `FinFunctionDict` to be
564+
# recognized as a subtype of `FinFunction`
547565

548566
FinFunctionDict(d::AbstractDict, codom::FinSet) = FinDomFunctionDict(d, codom)
549567
FinFunctionDict(d::AbstractDict{K,V}) where {K,V} =

src/categorical_algebra/Sets.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ show_type_constructor(io::IO, ::Type{<:SetFunction}) = print(io, "SetFunction")
6464
func::Any
6565
dom::Dom
6666
codom::Codom
67-
68-
function SetFunctionCallable(f, dom::Dom, codom::Codom) where
69-
{T,T′,Dom<:SetOb{T},Codom<:SetOb{T′}}
70-
new{T,T′,Dom,Codom}(f, dom, codom)
71-
end
67+
# Code review note: the code that was here before was apparently part of
68+
# something that was necessary in the context of an old implementation of
69+
# `SetFunctionCallable`, but is no longer
7270
end
7371

7472
function (f::SetFunctionCallable{T,T′})(x::T)::T′ where {T,T′}
@@ -107,7 +105,10 @@ end
107105
108106
Not to be confused with `Base.ComposedFunctions` for ordinary Julia functions.
109107
"""
110-
@struct_hash_equal struct CompositeFunction{Dom,Codom,
108+
@struct_hash_equal struct CompositeFunction{Dom<:SetOb, Codom<:SetOb,
109+
# Code review note: these additional restrictions, on the variables `Dom` and
110+
# `Codom`, allow `CompositeFunction` to be recognized as a subtype of
111+
# `SetFunction`
111112
F<:SetFunction{Dom,<:SetOb},G<:SetFunction{<:SetOb,Codom}} <: SetFunction{Dom,Codom}
112113
fst::F
113114
snd::G

0 commit comments

Comments
 (0)