-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notate class hierarchy as semilattice
If we were to imagine 'is-subclass-of' order-theoretically, then the class hierarchy is a ∨-semilattice.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Extension { #name : #Class } | ||
|
||
{ #category : #'*MachineArithmetic-MathNotation' } | ||
Class >> ∪ [ anotherClass | ||
"Join in the semilattice of classes partially-ordered by 'is-subclass-of'. | ||
SmallInteger ∪ Association >>> Magnitude | ||
" | ||
|
||
"Join of any two comparable elements is the 'bigger' one" | ||
self ⊆ anotherClass ifTrue: [ ^anotherClass ]. | ||
anotherClass ⊆ self ifTrue: [ ^self ]. | ||
|
||
^self superclass ∪ anotherClass | ||
] | ||
|
||
{ #category : #'*MachineArithmetic-MathNotation' } | ||
Class >> ⊆ [ anotherClass | ||
"Answer whether the receiver is a subclass of anotherClass, | ||
reflexive case included. | ||
Integer ⊆ Object >>> true | ||
Integer ⊆ String >>> false | ||
" | ||
|
||
self = anotherClass ifTrue: [ ^true ]. | ||
^self superclass ⊆ anotherClass | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Extension { #name : #UndefinedObject } | ||
|
||
{ #category : #'*MachineArithmetic-MathNotation' } | ||
UndefinedObject >> ⊆ [ aClass | ||
^false | ||
] |