Original citation:
Lehmann, D. J. and Smyth, M. B. (1977) Data types. Coventry, UK: Department of Computer Science. (Theory of Computation Report). CS-RR-019
Permanent WRAP url:
http://wrap.warwick.ac.uk/46317 Copyright and reuse:
The Warwick Research Archive Portal (WRAP) makes this work by researchers of the University of Warwick available open access under the following conditions. Copyright © and all moral rights to the version of the paper presented here belong to the individual author(s) and/or other copyright owners. To the extent reasonable and practicable the material made available in WRAP has been checked for eligibility before being made available.
Copies of full items can be used for personal research or study, educational, or not-for-profit purposes without prior permission or charge. Provided that the authors, title and full bibliographic details are credited, a hyperlink and/or URL is given for the original metadata page and the content is not changed in any way.
A note on versions:
The version presented in WRAP is the published version or, version of record, and may be cited as it appears here.
The
Univensity
of
Warwick
THEORY
OF
COMPUTATION
REPORT
NO.19
TI
ATA
TVPES
BY
JInTIEL.J,LEHMANN AND
11TcHAEL
B,St',t
yrH
Departrnent
of
Computen ScienceDATA,TYPES
Daniel ,J. Lehman#and Michaef
B.
SmlrthDepartment
of
Computen ScienceUniversity
of
War.wickCoventry, West Midlands,
CV4 7AL
Great
Britain
Abstract
-A Mathematical
interpnetation
is
givento
the notion
of
a
data .tJrpe.Ttre main noveltSr
is in
the
genenalityof
the
nathematical treattnentwhich allows procedural data't5pes and cincular"ry defined data
tlpes.
What
is
rneantby
datatype
is
p:rettxr closeto
what any corputenscientist
would r:ndenstand bythis
terrnor by
data stnuctune, tJlpe,mode,
clustenr
cl-ass.
The mathennatical trreatmentis
the
conjunctionof
the
ideasof
D. Scott
onthe
solution
of
domain equations (Scott(71),
(72)
and(76))
andthe
initiality
properry noticedby
theADJ gnoup (ADI
(75),
ADJ(77')).
The present wonk adds openationsto
the
data types pnoposedby Scott
and generalizesthe
datatlpes
of
ADrlto
procedur,al types andanbitrary
ci:rcurar tJpe
definitions,
The advantages
of
a mathematicalinterp:retation
of
data
tjrpes arethose
of
mathematical semanticsi::
genenal:
throwing]ight
on soreiIl-rndenstood
constnuctsin
h-iglr-leveI pnognarrning languages, easingI"
Introduction
Ali
pr"ogramming languages havebasic
datatypes,
some have many,some have
few,
sorne haveonly
onebasic
data'type.
The mostcomrnnly used ane
:
booleans,integers,
r:ea1s, procedures,Iabe1s, atomso
lists.
Theygenerally
come equippedwith
sorne openations: logical
openationsfon
booleans, a::ithmetical operationsfon
intege:rs andreaIs,
compositionn evealuation andabstnaction for" pnocedunes,
a defining
facility
fon
labels,
andlist-rnanipulation pnimitives fon
iists.
fn
most data..qpesthe
user. hasthe
facitity to
denote new objectsby the
useof
expnessions combining o1dobjects
by openationsoAi-l
thesefacilities
are
easyto
undenstand.
Thefi::st
non-tr"ivial fact
about data. B(pesis that, in
ce::tain data types andin
centain prograrming languagesnobjects
can be definedimplicitly;
they
ane definedby
e:pnessionsthat
containthein
own denotation"This
is
the
facility
whichis
gener"ally ::efe::nedto
as |tnecu::sivedefinitionf'
but
which weprefen
to cail
"circu.l-ardefinitiont'.
This
facility is
generally
offenedfor
pnoceduna.l- data types only.ln
the
most advanced ianguages(caIled
extensible)
the
user maydefine
new data ty-pes fnomold
ones bythe
useof
eonstnuctol"s.
InALGOL
68,
for
example, theserow,
fp$.
New ope::ationsdefi.ning new procedures.
constnuctors are
gq]}g!,
!!!!r
ref
3In
some languages,like
ALGOL68,
new data types mayalso
bedefined
cir"cula::Iy"
Thefollowing
twodefinitions
a::e examplesof
suchcincula::
definitions
in
ALGOL 68:mo.g
g
= gg!
( iE Iabel,
nef
t.ree.1eft, €
lgeg
::ight
)moi.e
fun = puoc ( frn )
firn-A11 languages known
to
the
authorsthat
al-Iow such circulandefinitions
of
data typesput stringent ::estrictions
on thegenenality
of
sucha facility.
Lehmann(77)
showedthat
many circul-a::definitions not
allowedin
ALGOL 68 are meaningful andve::y
useful.
The question
of
the
mathematical meaningof
cincula:rdefinitions
inside
pr.ocedural data types wasfinst
answened, independently, byH.
Bekic,
D.
Pank andD. Scott,
whonoticed
that
the
funetionsdefined wene
least fi>ooints
of
rpnotonefunctionals.
Thefact
thatmode-constructons ane
functors
was mentionedin
Scott (ZZ),
in
anemank
attributed
to
Lawvere, andlater
madeexplicit
by Reynoldsand Wand ( 74
).
Cir^cular.definitions
of
sets
and languages hadbeen known
to
algebraists
for"a certain
time when,in
1969, Scott gavea
pnecise neaningto
ci::cuLardefinitions involving the
function-space
constructor
(his
arnow,the
ALGOL 68Bggg).
A general methodto
solve
dornain equationsoirplicit in
Scott (72),
was rnadee>glicit
by
Relmolds.
Thecategorical
natuneof this rnified
construction,only
hinted
at
by Scott,
was emphasized by Wand(74).
The main idea behindthe
pnesent wor:kis that
the
pnoblems involvedin
definingoata rypes can
best
be handledby
an exactgeneralization
of
thewithin
a
datatjpe.
This involves
genenalizing fuom posetsto
categorieso fnom monotone
functions
to
frr::rctons, and fuomleast
fixpoints of
continuols functions
to initial
fi>rpointsof
continuousfrnctors.
The ADJ gnoup concentrated onthe
p::oblemof
definingfrnctions
on data types andinsisted
that
data types donot
consistonly
of
a
set
of
elements, st:3uctur"edin
some way(generally a
partial
onden)
but consist also
of
centain
frstctions.
They understood theimpontance
of initiality
andnoticed
that
certain
data t5rpes weneinitial
algebras (oninitial
rnany-sonted algebnas)but
wene unableto
include
procedr::na1 data typesin
thei:r
tl:eatment anddid
not
seethe
link
with
initiaL
fi:<point
of
continuousfunctonse
The nelationbetween our" wonk and
the
authotsjust
mentioned can be surunanizedas
fo11ows"
We pnovidea
categonical vensionof
Scottrs
domainconstnuctions
that is
sinrplen thanWandts.
At the
sametime,
wetake
fuII
accountof
the
ideasof
ADJ,while
avoidingthe limitations
to
equationally defined,
non-procedunal data types whichthein
approachentails.
Asto
the
mathematical resuLtsin
the
paPerr mostof
thesear
e
fai::Iy
obvious-
once one has gnaspedthe
ideaof
systematicallygeneralizing
fr:om posetsto categories.
The main purposeof
thewonk
is,
howevenrnot
to
Presentdetailed nesults, but
to
showthat
a
clean and ::igor"ousbasis
for
the
theory and pnacticeof
data tyPes canbest
be pr.ovidedby
the
conceptsof
o-categories,
ut-continuous2"
MathematicsThis section
wilL
intnoducethe basic notions
andnotations
to
be used
in
the
sequel.Definition
1:
A
Gimilanity)
type T
is
a
ranked alphabet.The nank
of
a
synbolis
calLedits
anity.
A
type
is
a set
of
symbols (intendedto
nepresentfirnctions);
to
each symbolis
attacheda
natunal number: (intendedto
be thenumben
of
anguments takenby
the fi:nction
nepresented),the
anity
of
the
s]rmbol. If
Tis
atype
TrrST is
the
set
of aII
symbolsof
nank n.lgIigi$l3:
A
(universal)
algebnaof
type
T
is
a set
S(called
the
eanrienof
the
algebr.a) andfon
eachn
€ N afi.rnctiond:T *S#.
'n
n
O-
'n :.ssociate:rwith
each synbolof anity n
a function
:
Sn+
Sof
the
cornesponoing nunberof
anguments"The fol-lowing
notions
of
category lheonywill
be assumedto
be known:category,
object,
arrow,
domain, codomain,icientity,
composition,snalr
categonies,limits,
colirnits,
products,
copnoductsn equalizers,coequaLizens, monics, episo isomorphisns,
initial
andtenninar
objectsn zenoobject, functors,
coseparators,well
powenedcategories.
TheDefinition
5Definition
6Definition
3 aris
the
categot:y whoseobjects
anethe
natu:ralnunber-s
: {
O,lr 2r
oo;
i' .." }
andthe
annowsall
couples(irj ) of
natunal nunbers suchthat
i
<
j owith
the
obviousidentities
and composition.C
is
an rrr-categoryiff
C has aninitial
object
andall
colirnits
of
ardiagnams.A
fi:nctor F
:
A-r
B is
an ar-fi:nctoniff
F presenvesaIL existing colimits
of
ar-diagnams.If T :
C+
C is
an endo-fr:nctona
T-algebnais
an
annow
(of
C)of
the
forrn g :
Ts+
gDefinition
4A
similanity
type
Tt,
asin definition 1,
can be considened as afutcton
Tin
the
categorySet.
An examplewill
showthis
bettenthan
a fonnal definition.
LetT' ={ o,
S} withrank (0) =0,
nank(S)
=
1
lT would be th-e firncto:r defined
by
TA =1 1
6 and Tf
=
Ia
+
f.
Then
aT-algebnawouldbeafr:nction
0:1 r S+S
andwoufdcornesPond uniquely
with a
set
(S)
equippedwith
one constant and one unaryopenationo
The neadenwill
easily
see howto
gener.alizethe
above exampleto
ar:bitnarysimilanity
t5rpes (eveninfinite
ones).Definition
7: IfT:
C+C is
anendo_functorthe categoryof
T-algebnas
is
the
categorSr whoseobjects
a!€
the T-algebnas and whose ar.t3ows, fr^on$ :
Tc+
c
tor/l
:
Td+
d
ane those arnowsa :
c+dof
C suchIf
T
connespondsto
a similar.ity
qrpeTr the
ar"rowsof
the
categorlrof
T-algebnas ane th-e tr"omonphisrnsof
tir-e univensal algebnasof
t3rpe T I .
A wond
of
cautionis
necessarlr heneto
warnthe
::eaderthat
ourdefinition of
a
T-algebna, though seeminglyonly
an extensionof
the
one foundin
Mac-Lane(71)
wheneT
is
al-ways supposedto
be amonad, has
in fact
a diffenent
purpose.
Thefr:nctor
Tthat
we maketo
conrespondto
a similanity
type
Tr
is
not
the
one Mac-Lane woul-dconside::
(the
onebuilding
the
caz':nienof
the
fueealgebra).
Ournotion
of
an algebrais identical to
whatArbib
and Manes (74)ealled a T-d5rnarrics"
We aneinterested
onJ-yin
the
case wheneT
is
an ar-frncton and C an co-category.
Tlreoryjn
3 :
Let
C be an o.r-categonyand
T
:
C+
C be an arfirncton,then
the
categoryof
T-algebr"asis
an o-category"Pnoof
:
Theproof
of this
theoremis
more-or-less noutinear':row-chasing"
As th-e existenceof
arcolimits
will
notbe used
in
the
sequelits
proof
will
beleft to
thereader.
Theexistence
of
aninitial
T-algebrawill
beproved
in
detail.
Let
r
bethe
initial
object
of
C(its
existenceis
ensur:ed because CThe
following
ar-diagrarn hasa
co-Iimit
(Cis
an &r-categony)r
-+
tr rfor
Tr
--l
"t2t V
r-\r
T3r-+ ...
Let
u.:
.IT-r +
a
bea
ooLimiting
cone. i,r-.tTlr,
: Tt'*g + Ta
is
a colimiting
cone becauseT
is
an apfuncton.I
Then thene
is
a
r:niquec :
Ta+
a
suchthat
oqTri=!i+1.
We claimthat
o
is
the
initial
T-algebna. SupposeB
:
Tc+
c is
a
T-aLgebra.Define
uo =!" and ui*1
=B
oTvi.uiorTr= l"
=
'o
and bYinduction
oni
:i +'t
ui+1o T
rO,
=B
o T( uio f''rTJ_)
= BoTui-1=vi,
and
the cone
,i
commnufes.Suppose
y :
a+'c is
an ar?rowof
T-algebrasa+c
ot
+8
Ta -)
Tc Tyyouo=
ynta =
I.
=Yo
and bY inductionyoli+1
=y,oo"Si
BoTYoT[i=
goT(yogi)=
B.bi
= vi+1and
y
hasto
bethe
unique arrow suchthat
ynli
=vi.
0n
the
other
hand,by the unj,versality
of y-
theneis
such a Y.Rema::k
:
Fnom Theonem 1 weshall
only
usethe
existenceof
initial
T-algebras andthe careful
::eade:: may have noticedthat
wedid
not
pnovethe
most genenal possiblenesults. InitiaL
algebras may be pnoved
to exist
evenin
categoriesin
which notall
or-diagrams havea
colilnit; it is
enoughto
supposethat all
a.r-diagrams
in
a
specified
subcategory havecolimits
(in
thelarge
category),
that
the
initiaL
elementis in
the
subcategoryand
is initial in
the
subcategory andthat
the
subcategor:fis
closed under
T.
Thesenesults
may beof
use when studying certaincategories wtr-ich a::e
not
or-categories,but the
sfunple versionnestnicted
to
ar-categoniesis
adequate for.the
purposesof this
Paper.
Theonem
2 :
Let
T be anendo-frnctor
onC. lf
a:Ta+a
is
aninitial
T-algebna thena
is
an isomo4rhism.Pnoof:agTa
B+
+
TBTa +
T2aTo
Initiality of
o
implies the
existenceof g :
a+Tasuch
that
B,co:
TcroTBBut
cropoo = doT(a"$)o
.e'+Ta
ac$ T
+
T(a.g)a6ra
whichl,
by
initiality of c implies
ooB = I=Then I
oc = T(cog) =T(I=)
= r__We want now
to
pnoceedin
giving
examplesof
the
application of
the
abovetheonems.
Our clairnis that
data 13rpgs can always beconsidened
to
beobjects
in
an appnopniate &r-catego4rr suchthat
each
data.tjfpe
constnuctoris
an ai-endo-furctorof this
category.Example
1 :
Set and univensal algebnasSet
is
eocomplete (andalso
complete) an6 sois
anar-categerlfe
1
!
SetxSet+Setis
an al-fi-urcton becauseit is
a pr.oductand
finitelimits
preserve dinectedco-lirnits
in set
(see Mac Lane1971 Theonem 1
p"
211)"+ :
SetxSet+Setis
an al-fu:cton becauseit is
a
copnoduct, and so
has
a
night adjoint
and pneser"vesall colimits.
Obviously constantfunctors
a::e ar-functo::s, compositionof
ar-functorsis
an arfuncto:rand a
bi-functon
is
an ar-functoriff it is
an a.r-fi:ncton sepanatelyin
each angument.Theonem
3
:
Let
T bea
similarity
typer
thenthe
associatedf,ncton
T :
Set+Setis
ancrfurcton.
The pnoof
is
obvious.
Theorem 1 and2
then implythe
existence
of
initial
algebrasof
anytype
andthe
fact that
the
initiar
argebna,as
a
furnction,
is
anisomorphism.
One knowsthat, in set,
notonly
initial
algebnasbut
also
ar"bitrar..y fr"ee algebnasexist
and also ar"bitnany f':nee algebrain
equational classesof
algebnas,but this
is of
nointer:est
to use
The existenceof initiar.
argebnaswas
known long befone
the
terrninitial
hadcredit for
the
abovetheoren.
The fnamewor.kof
r:nivensal algebrasis
too
restr-icted
for
data types and, as noticed by AD.], rnany-sortedalgebnas seem mone suited.
Examp]e
2 : Setn
and
n-souted, algebnas,Setn
=
SetxSetx.. oxSetn
timesSetn
is
obviously
cocomplete Cand al-so eomplete) and sois
an &r-categoty"rf T :
setn+
setn
the
T-algebnasar€ a
genenalizationof
whatis
called
in
the
litenatune
nanrso:rted a1gebnas, heterogenous argebnasor" algebnas
with a
schemeof
openatons.
Theonem2
implies
the Pr"oposition 2"1of
ADI(77).
Manysorted
algebnasar€
closen thanalgebnas
to
what one r:ndenstands data-ty?es shouldbe,
neventheLessthe
p:roblemsof
ci::curandefinition of
objects
inside a
data-t]rpecannot be
tackled
in
setn
fo::
Lackof
an o:rden structune on theobjects
(which ar€n-tuples
of
unonde:red.sets).
Burge(25) is
pnobablythe
besto though somewhatinformar,
accountof
what can bedone
with
sets.Example
3 :
o-€PO"
and continuous al_gebras.To remedy
the
absenceof
onden stnucture onthe objects
AD] (77)have proposed
to
use man]psorted a-Lgebnas whose canniens ane arcompletepantial
ordenswith least
element and whose oper€tionsare
a.r-continuousfunctions"
Ounobjection
to this is that
the
pnoblemof
circularly
defined data-tJpes nrtrose
definition
involves
the
arrow
(or: thenot
a
bi-fr:nctor
in
the
ahove category: it is
contravariant in
the
finst argunent.
We shall- neventh-eless showthat
oun nesults aIl-owa
verlr sfurpleproof
of
ADJ(77)rs
maintechnical
nesult
:rt
the
existenceof initial
continuousalgebnas.
Let
arCPO be the categorlrthe
objects
of
wtrichare the
ar-conplete posets (evenyc.rtiagran
aoSars..Er.',.Soo. hasa I.uob.)
witfr.least
elernents and thearrrcws
of
which anethe
str.ict
(bottom pneserving) co-continuousfr:nctions.
Markowsky C7a) showedthat
the
fuII
sr:bcategonyof
arCPO which
consists
of all
chain-complete posets (which he caLlsCPC
) is
complete andcocompleteo
Weshall
briefly
pause heneto
?t
prove
this result
fo:r r.r-CPO;
the
method used heneis
a definite
impnovement on Mankowskyrs. Neventheless these
nesults
will
not
beused
in
the
sequel both because we d,onot think
that
apCPO*i"
"
good candidate
fon the
categoryof
data t5pes and because, by usingthe
nemarkafter
Theonem1,
the
existenceof
aninitial
T-al-gebna*
in
al-CPO ean be pnovedfon
all
functons T which pneservea
specialclass
of
monicsfon
whichit
can be shownthat all
ar-diagnams(of
special
annows) havea
co-limit (in
orCPO*)",t
Co:SemLleleneE_s I'heonem
:
r.r-
CPOis
complete and cecomplete"rroof :
To prove completenessit is
enoughto
pnovethe
existenceof
products and equalizersof
pains
(Maclane(Zt)
p.tOS). Pnoductsin
ro-,CPO* anejust
Like
in
Sets;
it is
a
brivial
task
to
checkthat
the
prrcductof
c,rcompJ-etepartial
ondensLemma a
Pr"oof
Lemma b
Pnoof
that
the
u::ique mediating arrow froma
coneof strict
functions
is st:rict.
Equalize:rsof
pairs
in
r,r-CPO'lare
just like in
Set.-I
Theeqr:alizenof AiB
is h:Ar+A
where gt.
A'
=
{ a I
aeA,f(a)=g(a)
}
witn the
ondening induced bythe
one on A andh is
the
injection.
Ar
is
anurcomplete CPO because
f and g
are
str"ict
which impliesreAr
andf
andg are
o-continuous. h is
obviouslystnict
andcontinuou.se
Nowto
pnove co-completeness,by
Her:nlich and Stnecken(73) (23. I+
p.
163)it is
enoughto
provethat
ur-CPO*is
well-powened, and hasa
co-separaton.
o-CPO*is
easily
seento
be well-powened.Let 2
=
{ rrr }
bethe
two-points r.r-CPO onder byt f l.
If f :
A+
Bis
a monicin
61-gp6'l thenit is
one-to-one. Supposef(a,)
T2-I=-f(a^) for f monic"
Let
h.:
2+A bedefined
fon
i
=7)2
byh"(r)
= -L andh.(r)
= uioFor
i
=!r2, n, t"
a
stnict
ur-continuousfunction
andh,of = h^of * h. = h^ * E, = IZlZLz d^
2
is
a
co-genenatorin
orCPO".Suppose
fng
are
tffo diffenent
arnows:
A+
!.
Then 3 aoeA
suehthat
f(ao) +
g(ao)
and by symmetry we may supposef(ao)
.f
e(ao).Let
h t
B +2 be defined by h(b) ={* (, i€ t^ r--f,
ur""
!
s(ao)CJ-ean1y
h
is
monotone and continuous.0u:: Theonem
1
then i,qBliesthe
existenceof
aninitial
x-algebnafon
any nanked alphabetE,
whichis
the mainnesult
of
ADI (27).Obvior:sly
the
same hoLdsfor
manrsonted continuou^s argebnas, whichar:e
ur^functonsin (
ar-CpO*)n.
Categoniessligirtly
diffenent
fnom al-cPo",foo
examplethat of
ar-complete cpors andstnict
A-complete cpots andstnict
A-continuous maps anen bysirnilan pnoofs,
seento
be ar-categories andthe
rnspyinitiality
results
of
ADI(77)
can be obtainedin
a
rnified
way,if
onethinks
these aneintenesting.
?he categony whoseobjects
anesountably based algebnaic posets
with least
elements and r+hose amowsare
stnict
ru-continuous maps which preservefinite
erements,inspined fnom councerle and
Nivat (za)
is
also
cocornplete(
andcomplete) and hence an ar-categorSrc
This
last
nesuft
can be proved either"by
the
method used aboveor
bynoticing
that
the
categoryis
equivalent
to that of
pa::tial
ordens andstnict
monotone functionswhich
is
venyeasily
studied"
rn all
preceding examples theconstruetion
of
Adanrek C?4) ens'::esthe
existenceof
anbitr:ary fneeT-algebnas over any
object.
0r:::insistence
that
T be an o-fi:nctonguanantees
that
the
fnee T-algebnas ane obtained ascolimits of
ar-diagrams.
ADJnoticed
that
expnessionswith
vaniabl-es nepnesentedobjects
in
such finee T-algebnas and madetotally
cleanthe
way suchobjects
yield
maps fromthe
envirrcnnentto
the
obviousdomain.
rnthe
sequel weshalI
admitwithout
funthenfornalities that
expnessionsouiLt
out
of
constants, vaniables and. (continuous)frnctions
yieJ.dExample
4
:CP0o and,ci:rculanly
defined data'tJpes.Let
CPOa Ca standsfor
adjunction)
bethe
categorythe
objectsof
rdrichare the
or-completepantial
onder:s(the
same objectsas those
of
ar-CPO*) andthe
arnowsof
which
f :
A+
B ane thepains
of
rrr-continuousmapsr
=
lrlrrRl *:
e+BandfR: B+A
l-L
-L-R--Such
that t ot
=
tA and f ol !
IB.CPO.
is
indeeda
categoryo
Thethe
readens.f
=
(rorro) is
an anrowof
cPoa.:
B+
C ane anrowsin
CPOa thenthe following
lemrnas pro\repnoofs
are
tnivial
andieft
Lenuna
1: f: A+A
definedthat
to
by
Lemma2:If f:A+Band
gir
=
(gL."*,
S.gR)
is
an Elrnow:
A+
C.The anrows
of
CPOaare the
painsof
pr"ojectionsof
Scott (ZZ),
ttreembeddings
of
Su5rth(75).
Wand(74)
seemsto
have beenthe
finst
to
state
that
the
fuII
subcategor5rof
CPOaconsisting
of
completelattices is
anar-category" Plotkin
(20)
andthe
authons noticedthat +r
x
andthe function
space constnuctor"(+)
were a;-fwctonsin
CPO-, sosirnplifying
Wandts(7a)
tneatnent which uses anon-standard
notion
of contjauity.
Lehmann(76)
pnoves a mone general statement fnom wtr-ichthe
fact that
CPoais
an ar-category andx,
+,
+ ane ar-functors at:einstant
conoll-anies.
Centainfull
subcategoniesof
CPOa:
the
category SFP-Rof
Pl-otkin,
the
categoryof
algeb:raicconsistently
conplete cporsnthat of effectively
given algeb:raicconsistently
cornplete cpors have been shownto
be al-categoniesthemselves by
Plotkin
andSmjrth.
Theyalso
ane closed rmden xr
*
and
'+.
SFP-Ris
aLso cLosed under.the
powe:: donain const:ructon PSmyth (76a) has defined
a
subcategoqrof
CpOa containing."
objects
onl]rthe
effectively
given continuous consistentlycomplete
cpors
v,rhichi-s
closed undenxr *,
+
andpor
and centainar-col-imits.
Unlike
all
pr"evious examples CpOa66""
not
possessprrcducts on copnoducts and Adarnekrs
(Z+;
o."*t
about fr,ee algebnasis inapplicable.
Yet by Theonern2
initial
T-algebnasexist
forarbitnary
arfunctoreiT.
Now some obvious lemmaswill
be statedwith
only
hints of
prrcof
onwithout
pnoof.Lemma
3 : rf r
=
(fLrS) i"
an annowin
cpoa, then any oneof
fL
o"
S
ur,iquely detenminesthe
other,"P::oof :
SupposeC*,
rrR)
and(flrfr*) u""
ar:rowsin
CpOa thenf
R_ €
R€LfR r.
c
F-I - -2 - -t
=
.2
and s5nrrnetr:icalIy.!@
t rf r
=
(*rd)
is
an arxnowin
cPoa:
A+
B thentLt, 'r P
r trA)
=tB and
Et(ra)
= ro.
Lemma
5 : J,
the
ons-pointpartial
onderis initial in
cpoa.Lgrmna
6: rf fL: A+Band d, B+A
ar"emonotonefi.rnctionssuch
that
d
i=
,r-continuous,
J"*
=ro
and*orR
c r,
then
fL is
ur-continuous.The
following
lemmas pnecisethe facts
about
co-rirnits
in
cpoa.The
finst
lernmais
a
concrete pnoposition about CpOabut
aII
following
ien-rinas may be proved
in
the
abstract
fnameworkof
or.der-ennichedcategonies and applieci
dinectry
to
othen categonies,in
particuJ_anf
f-
f.
Lemga
7 : Let t, od' oo, *t o, * *0, *tor*, * oo.
be anr.r-diagnam
in
CPOa.
Theneexists
a
commuting coneu
:
t * A-
suchthat
fon
any
:rer
,l ,l !
ul*, ul*,
LR
anc
U U-. U-_: tn
.ilrd_
Pnoof : tet
A-
=
{ (
ron.1eoo.d.e..
) | viefi
"i.Ai
anda.=flui*r
}ordened
by
componentr^r-iseordening. A-
is
an ar-completepantial
ondenby
Lenrma4
and becausethe
{
ane&r-continuous.
Thearlubrs in
A- are
componentwise"Let
pi
A-
*
Ai
bethe
ith
pnoSection :P1
( (
ao,
orElir
.. > ) =.i o pi is
ol-continuous becauselubts
in
A-
ane componentwise.Let
qi :
A,
+
A_
be defined byP D N .L J.L
giui
=<
fo
fi-t
"i'
'ff_r.i,
ai,
ti"i, { ti
ai,"o.
)
oClean1y
e, is
well-definedr
rrnnotone and, Vieffq
=gi+1"{
,Furrtherrnor.e
Pi4i
=
tO, and eiopi.
tO_
sothat by
Lenrnas3
and 6,u
-
{gio
pi)
definesa
commutingcone
[r+
A_ in
CpOa.q,i'
Pi
=9i+1
. fl
"
{
. nr-*,
5
qinr
o pi+1.!
,n,
. pi)
5
re_
because
9i
o
pi
g re*
,
yieNVje//
pj ",!n, "nr)!n, o9j
opj
=pj
whichirnpriesthat
pi "(Uq.t oPi)a.orerordi..o)=di
and (!g,
op;):Io
oB
J 1 ! ! v r J i -L -L A_
in
the next
lemmasall
&Fsequencesof
firnctions fon
whichI.u.bts
areLemmgr
8
:
Let
f
(as
in
Lemma7)
be an trr-diagnamin
CPOa.If the
conev : | +
Bis a coliniting
cone(in
CpOa)then '|r L
Rluiui=tn
Pnoof :
Let
y : | *
A-
bethe
cone definedin
Lemma7.
Theneexists a r:nique
h :
B+
A_
suchthat
hou. = Ui"L .L t
R
R.R
rnen xi
=n ov. and lri
=Vloh
.. _.R_.L_.R
r
P tt, L R. ,L
,,,R L R.L
I, =h"ol" =h"
o
IA_oh"=h"o (
lpiu,
)
"tr"
= ljh'toUi"ul"n,
.R
.L
= r-t h-'o
n-
.ul
.
,i"
hRohL
= Uul
.
ul
.ilar
LeUnlg
9 :
Let
I
be an ur-diagramin
CPO.and u : I * A
be aconrnuting cone such
1'
L
R
L:nat
u
uiui
=tA_ then ui
rsa colimiting
conein
ur-CPO*for
fL.
Proof :
Cl-eantyp!
commutes.
Supposec: |
.+ Bis
ar!*
commuting cone
in
rrl-CPOand
h is
an anrowt
4_*B in
o-CPO suchtnath.ul=di
then h=horA=ho([jufuR)=U'LR
'
Ri r-
inuiui= loiui
which proves
unicity.
Fon existence
tet
h
=d
oiul
.
rhenh"uf
=!=ioiufu!
=I
RL_L
-L
,,
_L
J
f>ioiuiui?r'"'tj-
=!=ioiti-r'"'T
=!=joj
=oj
oLemma
10:
Withthe
same hypotheses asin
Lermagr
rl is
a
limiting
cone
fon the
uroP-diagnamrR
.P::oqf :
This
is
the
dual
of
Lenrna9
(neve::sethe
anrowsbut
notthe
order.ing on annows )Lemma
II :
Let
f
be an ar-diagnanin
CpOo andu : |
+ A_ be aconrmuting cone such-
that uL is
a colimiting
cone in
&-,! t.
o-CPO
fon
f"
thenp
is
a colimiting
cone(in
cp0a). Pnnnf . e"nn,uL
,
rL
* B is
a
cormuting conein
to-cpo* and theneexists a
uniqueh :
A-
+
B
suchthat
heyl
=vf .
By Lermra3 this
provesrrnicity.
To pnove existenceit is
enoughto find
a
night-adjoint
to
h"TDLT.Rr.r.l.p
(
uul
v-:')
oh
oul
=il uivluf
=uf
>
(
i.rui
vf )
oh
=
r^i'r
t
'l
i>3
'r
r_
I
'l
-
i "i
-i
-
-A_h
o
(
f
'l,l
)
=u
n
ul'l
=!"1
uf
cr,
IA L R
( n,
!
ui
"i )
is
an amowin
cpoa.
DLenma
12
: Let I
be an ardiag:ramin
CpOa and U: |
+
A_
be acomnuting cone such
that
irR
is
a
limiting
conefon
IRin
ar-CPo*r thenu
is
a colimlting
eone(in
cpoa).E_::oof :
Dualof
LemmalI.
Definition :
Let
E,
bethe
covariant
enbeddingof
cpoain
ur-cpo*which sends each
pain
of
functions
to its left
par:t andE* be
the
contravaniant embeddingof
CpOain
r,l-Cpo* whichsends each
pain
of
fr:nctions
to its
niglrt
pant.
cleanlyE,
and E* anethe
identities
on objects.Theorem
4 : l)
CPOais
an 0r-qatsg6rSr2)
E,
pnesenves and::eflects
ar-co-Ifunits3
)
E*
t::ansformsor-co-limits
into
aroP-linits
and neflects,oP-lirnits
into
ar-co-1imits.Pnoof
: 1)
by
Lemrnas5, ?,
9
andIL.
2)
by
Lernrns 8 and9
and LernmalL.
The
next
TheonemwilI
be usedto
plove
that
frnctons
(on bi-functor.s)in
CPOa ane o;-functor6.Theonem
5 : If
T
is
a.n endo-functor on CpOa Ca bi-fr.mctorCPOa
x
CPOa+
cPoa) o T presenves a,-colimits. if
fonevery sequence
=
* J
^o
'o
I':_
c
* J - -'L'8 -
*1=""3'i 'i l: ""
H
rl
{
=r
}
U(r
ri)
L
(r
r.;R
=
1.:
By Lemmas8,
9
and 11.e*
CPO-, can
be
considened asa
Cnon-full)
subcategoryof
o-CPO; if
**
Tr
: rrr'-CPO" +16CPO pnesenves adjunctionsits
restniction
to
CPOais
a
fr.rrctonT :
CPOa+ CPOa.
Thefollowing
theonem showsthat
the
initial
T-algebnais
also
aninitial Tr-algeb:ra. It is
usefulto
d,raw moner.adical
initiatity
pnopentiesfon the
data epesci:nculanIy defined
by
definitions involving only
+and x (at
theexception
of +),
as ttrose eonsideredin
ADJ (75).Proof
Theonem 6
Pnoof
:
Let
T :
CPOa+
CPOa bea
fi.rrcton andTr :
ar-CPo?t+ ar-CPO* an a.r-fi:ncton suchthat
ErT=
TrE,
thenT
is
anar-frmcton and
if
6
is
the
initial
T-algebra thenEl,0 is
the
initial
Tr-algebna.:
Tt is
an 4v*fplsfoD by hypothesi.s andE,
is
an arfi:nctonby
Theonem4
=) TtE,
=ELT
is
anar-fi:ncton.
But by Theonen 4E,
r.eflects
ercslimits
and thenT
is
anr^r-firrctor"
TheonemI
assents
the
existenceof
g
:
TA+
Athe
initial T-algebna.
Thepnoof
of
Theorem1
showsthat { is
the
r:nique arnowin
cpoa sueh t}ratBy Theonem
4,
E,
pnesenvesarcolimits and
Ei,!colimiting
cone.
Becausethe
initial
object in
initial in
ar-cPO'!,E,t is
the following
diagnamErf
i r ,*
Ttrh..r?
l'', * .... * t'i :
-.-TtL
t *TtL
lrtrrr,
:Erf+A
isa
cPOa
is
also*
in
aJ-CPO :,ri+1 * "...
The pnoof
of
Theor"em1
showsthat
the
(upto
isomonphism)initial
Tr-algebna
is
the
r:nique arrow0 :
TtA+
Aof
ar-CPO* suchthat
Vie/[ {
oTtELIi
= Etui*:.But
Elui+t
= EL 0o
E,
Tu.
= EL0 o
TfEru.and ,t=Et0.
tr
*
Remank
:
Ma::kowskyts(7+)
r'esu1t onthe
cocompletenessof
CPCis
not
used.
Cinculanly defineo data.typesthe
definition of
whichinvol-ves
+ (r:nion), " (E;ggg)
and
* (9,)
can be seento
beinitial
algebrasin
CPOao aswill
be expiainedin
the
sequel (seeLehmann
tZZ)
for
a
previeworiented
towards ALGOL68).
Scotttsoriginal
(ZZ)solution
to
domainequations
consistedof
consideningthe
subcategoryof
CPOa whoseobjects
a:re continuouslattices
andwhose arrows
are
painsof
A-continuouspr.ojections. It
can beeasily
checkedthat this
subcategoryis
cLosed under o-col-imits.Scott
(ZO) proposes anoth-endefinition of
datatlpes
and neduces thesolution
of
comain equationsto
least
upperbornds.
Plotkin
andSnryth have necently shown
that
thesel.u.brs
al.e r,r-col-initsin
asuitable
categoryof
adjr:nctions whichis
equivalentto
the
subcategoryEx€inple
5 :
Dom anda
mone genenalnotion
of
a
data-t54pe.Lehmann
(76)
defineda
catego.r'y Donthe
objects
of
wh-ich aneorcategories and
the
arnowsof
which a:re adjr.rnctionswith identiry
nnit.
Dan Ls an ar-categoryand
X,
*,
+
andp
can be definedto
bear-frtrctor.s.
cPoais
a
furl
subcategonyof
Dom closed undena.rco-lirnits,
X,
tr
and+ .
The eornespondentsof
rheonerns 4 and 5hold
andnelate
Dorn and, ar-Cat,the
categoryof
ar-categoniesand
stnict ar-functons.
bm
provLdesa
more genenalnotion
of
a data typenuseful
whenthe
powerset constnuctor, ou non-deterministicpnocedu:raI Qpes
are
allowed.we
shall
now proceedto
give
a nurnbenof
examples showing howci::cu1a:r
type
definitions
do indeeddefine
initial algebras.
Thealgebnaic aspects
will
be stnessed:
a cincular
t5rpedefinition
doesnot only
define
a
pantiari-y
ondenedset but
also
sornefi:nctions
onthis
set.Exanrpfe
6 :
Ttrenatr:ral
numbers.T'l:e
naturel
numbens,or
eventhe
integens, are generally
thoughtto
be abasic
data'tJpe.
I{eshall
now demonstrate howthey
can becir"culanly
defined"
our
treatmentis
equivarentto
Lawverers (64),as reponted
in
Maclane-Binkhoff(62) (pp.
62-70).Let
oul: r:nder.lying category beSet,
I
bethe
one-point set(it is
a terminal object
in
Set and aLsoa
generaton), r
theiet
T bethe functor
definedby
:if e isaset
Te:J+e
if f :
"1*
"2
is
a
function Tf :
Tea+ Te,is
the
fu:action definedhy
(Tf)(u)
=
ft if
a
e ear if aeJ
In
categorytheonetic
notation Tf
=
I,
1
5Clea::Iy
T is
a
fr.:nctots:
Set+ Set. It is
indeedthe
firrcton
associated
with the
simiLanity
type Tt
=
{
OrS}
nank (O) = O,nank
(s)
=
1
descnibedafte:: Definition
6"
T
is
an orfuncton, asall
firnctons associatedwith
sinilanity
tlrpes,
as explainedin
E><ample1.
By Theonern 1 ther.eis
aninitial
T-algeb::a,g :
1
+ A+
A.
Theinitiality
property
of
g
cha::acterizes, up toisoroo4>hism,
the
fr:nction
O+ suc z
1+
N+
N which gsnds,lef
to
zeno anci ne/l/
to
n
+1
= suc(n).Lemma
1 :
0
+ suc
:
1 + N+
N is
the
initial
T-algebra.Proof
:Suppose
{:J+B+B
Suppose q,:
y'/+
B.If (f)
o
"
(O+
suc)
=0
o
(Ir+ cr)
then(z)
a
(o)
=
(
o o (0
+
suc))
(r)
=
(
0
"(tr+ a)) (r)
=
6
(r)
(S)
o
(n
+1)
=
(
o
o(O+
suc))(n)
=
(
O.(rr+
a)(n)
={(o(n))
Converselyif
o
ve::ifies (Z)
and (3)c
o(O+
suc)(r)
=c (o)
=6 (r)
u
o(,O+
suc)(n)
= cr
(n +
1)
=0(cr(n))
andBy
the
induction nule fon the
natuml
nr-unbens theneexists exactly
onefrnction a : il
+
B
ver:ifying
(2)
and(3)
andthis
pnovesthe
initiatity
ofO+suc:L+N+fl.
The
point
we wantto
make heneis tiut
the tlpe
/[
can-be
ci:ncularlydefined
by
:
tr
=1
+N or in
ALGOL 68notation
modenatrr:ral
=union
(t"fr, natunal).
Theinitial
ffurpoint involves
not
only
theset fl but
also
the
constant0
andthe function successor"
The induction::ule fon
natural
nunbens whichis
vital"
fon
pr:oving ptopentiesof
prog:ramsmanipulating
natural
numbensis
nothingelse
than aninitial-iry
propenty.fn
other
wo::dsthe
fact that
the
rnique o :
// +
Binplied
by Theor"em 1is
a
total
fturction
is
the
maintool in
prrcvingthat
centain fi:nctionsare
total-, in
contr"adistinction
with
the
more generalpantial
fi:nctionswhich may be defined
cincularly
inside
[ /il+
B]
bymeans
of
arbitnar:ycontinuous
rirnctionals
: [ff
+
BI +:[/t/+
B]"
Fo:: othen
cincurarly
defined data typesthe
initiality
pnopenty may oftenbe used
Cirectly
in
placeof
an ihclrlctionprinciple. fn
othen casesit
is
the
maintool in
pnovingthe
connectnessof
aninduction
principle.
Thequestion
of
the
exactrelation
betweeninitielity
andinduction
will
betro:f pd in Soni-r'nn q
A-1
useful
fr:nctions
on natu::a1 nr.unbens maybe
defined f::om0
+ sucwith
the
help
of
Lemma1.
The usualdefinition of
addition
for
exampler:.''
be neadil-y transfonrnedto fit this
fr^amework.n+m=r
if
m=0Let
T =
trf cr: * f) and u:
T(Iffdlll).+
[N+N]be definedby
:
,lt=
TN+
lf
(suco f).
Then thene
is
a
unique
u :
d
*t il+ryl :nakingthe
foll-owing diagnam comnste.N t$t
J.+N
i
"
!
rr*o
r.,.'[,
[ff*fl] S
L+[N+Nl
The commutation
of
the
above diag::amis
equivalentto
: a(O) =If
and
a(sucn)
=
Suco
cCn)a(O)(m) =
m and
c(sucn)(m) =
Suc (a(n)(m)).o
is
the
addition"
More genenally any
function
defjnedby a
pnimitive
necunsive schemeis
the
unique annor{ rnakinga
sfunilan diag::arncommute"
Ce::tain suchdiagnams, howeven,
define functions
which a::enot
pnimitive
necursive"Theonem 2 assents
that
0
+ sucis
an {g.omonphismrits invenseis
obviouslynuii*pr"ed: N+7tN
defineciby
(nutt+pned)
(O)=rand
hull-
+ pned) (n+1):
nThe p::oof
of
fheorem2
shows howto
define
pnedin
termsof
suc.Let
TS=
I
+I/
+fl
+
S.
Theinitial
T-algebrais
0 : f
+ N + N + Nx
/y'=
(J.+N)(I+W1+
d
x
lV definedby
d=
Co+suc)r(olsuc).
Let 3=
{tr:ue,
false} andrl,:
J
+N+ /[+B+Bbe
definedby
0(r)
=tnue,
$(nr) =
OCnZ): false
and4(b)
= b"(o+suc)xCo*suc)
7+N+N+NxN
I I
I
Ir+
Irr+I,,+
clrwtv
lL L+N+N+B
a
is
the
r:nique ar.tsow: I
x
il
+
B
suchthat:
o(OrO) =
tnue,
c(n+1rO):
c(0rm+1) =false and
c(n+1rm+1)=
c(nrm).a
is
the equality
pr.edicate.Examole
7 :
Context-fnee languages.All-
l-eastfi:points
methodspreviously
rr^sedin
Computen Science anespecial
casesof
the
mone gene::al category-theo::eticinitial
fixpoints
presentedhereo In
partieular the
charaetenizationof
context freelanguages
as
least solutions
of
a set
of
equations canbe
ca:rried th:rough.Let
)
be an alphabet(not necessarily
finite),
thenP(x*),
ttrc set
of aII
languages oven
X,
ondenedby
inelusion,
is
a
completelattice
and, bystandand methods, an 0r-categor..yo
Let
V*
be an alphabetof
non-terrninals(not
necessanilyfinite)
and p bea fi:nction
:
V* -r E where Eis
the
seta-:.
expr"essionsbuilt
fnornV*, f,,
concatenation anduniono
0nP(ft')
concatenation and i:nion ar"eadditive
Cthey pneservearbiilrany 1.u.bts)
NxN
I I
I
+
and so
they
ce::tainly
ar?e &r-.fr:nctors p
clear"ry defines anal-fwrctor
:,',
lVuI
rt
lVnt IT : P(f")' "l *
Pcf,")r
N'
andthe
initial
T-algebra TAc
Ais
the
1easti,, r - -.
rt-lv*l-ulle
Aof
subsetsof
PCI)
suchthat
TAc
A.
By theonem 2 TA = d.Exarnple
8
:
Context-fnee g?ammars.A much mone
intenesting
example concerfnscontext-free
grarmars (as opposedto
languages).
A context-fnee granmanwith n
non-terminalscan be viewed as an rrr-endo-furcton
T :
setn+
Setn,
in
a
manne:: similar:to
example T above,but
whenu (of
sr$sets
of r't) i"
nepLacedby
+(aisjoint
union)
and.
(concatenationof
subsetsof
x't) by
r
(pnoduct).Fo:: example
the
context-fnee gramrnar:
s
+ alasafassal
can be ]-ookedat
asthe
functon
: T :
),S.{a}
+
ta} x
S x'{a}
+'{a} x
Sx
Sr'
{a} Theinitial
T-algebna
g :
TA+
Aconsists
of a
set
A isomorphicto
{a}
+
ta} *
A x'{a}
+'{a}
x
Ax e
x'{a},
venifying
the
initiality
property.
Ais
isomorphicto
the set
of all
parsetreeso $
constructspanse tnees
and 0-1
decomposes parsetrees.
Note her.ethat
thefuaction
fnontier : fr. :
A* f,*
which assignsto
each parse tnee thewond generated
is
not
one-to-one and fo:r wexft: lrr-1{w)l is
the3.
Data types as aLgebnaswe now want
to
makeour
thesis
pnecise:a
datatype
is
anobject
in
a suitable
categoryof
domains (CpOa wil-l- dofor
alL
applications
henebut
Domor
othen categonies could be considened) equippedwith
centain operations.Def.initionJ:
Atype
t
consists
of
a
natural
numben n>o andn
pai::sof
functons(SirT.), SirTi ,
CPOa+
CpOa,i=lr...rn
Definition
2:
A datatype
Dof
type
t:(nrS.
rT.)
consists
of
anor-CPO D
(with
light
notational
ambiguity) andn
(6-continuous)fr:nctions d. :
'l- S.D+
T.D.l_ t_
rn practicat
applications
the functors
s.
andr.
usedare
always"polynomial'r
(ttrey
arebuilt
f:rom pnoducts and sumsonry)
and indeeda
datatype
is
a
domain equippedwith a
finite
numbenof
functions.Definijion
3:
A homonorphism fromD,
to
D,
of
type
t is
a
fr.nctionf :
Dl
*
D2 suchthat
the following
diagr.am commute:o-.1
S,D. -+
tl- T.D-l_l_s.r
11J
i
r.r
I i,
"i"2 . 2 'i"2
9i
Homomorphisms
wirl
be usedin
section 6
to
study inplernentations.For