Skip to content

Commit

Permalink
Notate class hierarchy as semilattice
Browse files Browse the repository at this point in the history
If we were to imagine 'is-subclass-of' order-theoretically,
then the class hierarchy is a ∨-semilattice.
  • Loading branch information
shingarov committed Oct 12, 2023
1 parent 84768e7 commit dab8217
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions MachineArithmetic-MathNotation/Class.extension.st
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
]
6 changes: 6 additions & 0 deletions MachineArithmetic-MathNotation/UndefinedObject.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #UndefinedObject }

{ #category : #'*MachineArithmetic-MathNotation' }
UndefinedObject >> ⊆ [ aClass
^false
]

0 comments on commit dab8217

Please sign in to comment.