On parametric algebraic specifications with clean error ... - Springer Link

14 downloads 0 Views 679KB Size Report
On this basis error and exception handling is studied. For each sort an ok and an error subsort is introduced and clean algebras (i.e. algebras which are ok/error-.
ON PARAMETRIC ALGEBRAIC SPECIFICATIONS WITH CLEAN ERROR HANDLING

martin gogolla I n f o r m a t i k B, TU Braunschweig P o s t f a c h 3329,

D-3300 Braunschweig

ABSTRACT Usual a l g e b r a i c s p e c i f i c a t i o n partially

ordered s o r t s .

s u p e r s o r t s as w e l l tures

(e.g.

t e c h n i q u e s can be e x t e n d e d t o t r e a t

This a l l o w s t h e i n t r o d u c t i o n of

as o v e r l o a d e d o p e r a t o r s ,

existence

of

initial

a l g e b r a s and

a l g e b r a i c and o p e r a t i o n a l s e m a n t i c s ) o f tion

method

handling is

are preserved. studied.

On t h i s

proach tric

1.

equivalence

of

the equational specifica-

basis error

and

exception

a l g e b r a s which a r e o k / e r r o r -

and o k / e r r o r - c o m p l e t e ) a r e

considered.

a l l o w s t o p r o v e an e x t e n s i o n lemma f o r

specifications

fea-

For each s o r t an ok and an e r r o r s u b s o r t i s

i n t r o d u c e d and c l e a n a l g e b r a s ( i . e . consistent

sub- and

while pleasant

T h i s new

ap-

p e r s i s t e n t parame-

which p e r m i t e r r o r h a n d l i n g .

INTRODUCTION

During

the

promising

last

method f o r

programming approaches

tics

and p h i l o s o p h i e s f o r

final

[ 8 8 M 76,

opment

of

[EFH 8 3 ] ,

Partially treated etc.].

the specification

Among them a r e i n i t i a l [Wa 79, WPPDB 83, Ga 83] ST 8 5 ] .

specification

proved t o

be

There a r e

many such

[ADJ 76, ADJ 81, EKMP 82, and o b s e r v a t i o n a l seman-

Research i n t h e f i e l d languages l i k e

a

a b s t r a c t data types in

the a l g e b r a i c semantics of

led to the

OBJ [FGJM 8 5 ] ,

develACT

ONE

ASL [SW 83] and many o t h e r s .

ordered

sorts first

introduced in

i n a s e r i e s o f p a p e r s EGo 83, They a r e t h e b a s i s f o r

handling,

of

languages and s o f t w a r e e n g i n e e r i n g .

specifications. K1 84]~

years a l g e b r a i c s p e c i f i c a t i o n s

a t o p i c which i s

Po 84,

[Go 78] 8M

84,

have G~M

been 85,

our approach t o e r r o r and e x c e p t i o n

studied extensively in the literature

82 [ADJ 76, etc.].

Go 77, The

clean

Go 78,

BGP 82,

GDLE 82, Bi 84~ Po 84, BBC 8b,

fundamental new n o t i o n s i n t r o d u c e d h e r e a r e t h a t

a l g e b r a s and c l e a n s p e c i f i c a t i o n s ,

ok/error-consistency allows

and

where c l e a n r e f e r s

ok/error-completeness.

t h e use o f pure e r r o r v a r i a b l e s ,

before.

In

the

specifications

literature

o n l y [Po

This

approach possible

84]

considers

i m p o r t a n t because s p e c i a l problems a r i s e h e r e .

to

the

exception

extension

lemma

By t h i s

[Eh 81] and use i t

approach, guaranteeing the w e l l

parametric

which i s q u i t e

[Po 84] works w i t h

whereas we c a r r y o v e r p e r s i s t e n c y

h a n d l i n g case.

of

to

which was n o t

in connection with e r r o r handling,

non p e r s i s t e n t s p e c i f i c a t i o n s ,

of

we can a p p l y

for

definedness of

our

the

clean

R-

algebra

the a p p l i c a t i o n of

parametric specifications.

The paper i s o r g a n i z e d as f o l l o w s . i d e a s by means o f tal

definitions

fications.

some examples.

Chapter 2 i n t r o d u c e s t h e b a s i c Chapter 3 r e v i e w s t h e fundamen-

and f a c t s c o n c e r n i n g s u b s o r t s i n a l g e b r a i c s p e c i -

Chapter

4 t r e a t s c l e a n a l g e b r a s and c l e a n s p e c i f i c a -

tions.

Chapter

5

d i s c u s s e s p a r a m e t r i z a t i o n and

lemma.

Chapter

6

g i v e s some s h o r t c o n c l u d i n g remarks.

space l i m i t a t i o n s

2.

all

our

extension Due

to

p r o o f s are omitted.

THE BASIC IDEA

Our

main new c o n c e p t f o r

a clean algebra. for

the

ok

e r r o r and e x c e p t i o n h a n d l i n g i s

T h i s means t h a t our a l g e b r a s have two

and e r r o r p a r t o f each s o r t and

ok/error-consistent

(there

the

error).

The approach i s e x p l a i n e d b e s t by an example. Here i s our of

t h e n a t u r a l numbers.

s o r t s Nat opns

0 : - > Nat-Ok Succ: Error

Nat-Ok - > Nat-Ok : ->

Nat-Error

ok

and

and

spe~ N a t u r a l N u m b e r s W i t h E r r o r H a n d l i n g =

either

ok

are

error)

specification

( e v e r y element i s

subsorts

carriers

i s no element which i s b o t h

ok/error-complete

t h a t of

or

83

Succ,

Pred

:

Nat - > Nat

Plus,

Times :

Nat N a t - > Nat

vats

n : N a t n+,m+:Nat-Ok n - : N a t - E r r o r

e~

Succ ( n - ) Pred(O)

= n= Error

Pred (Succ ( n + ) ) Pred Entry-Error

Tree :

has

(2)

function

The

The f i r s t

occurrence such

one.

Entry-Ok ->

Tree-Ok

to the

corresponding to

(4)

important to

It

is

= O, o t h e r w i s e t h i s

(6)

and

axiom

for

derived

variable

the function

essential

use

can be c l a s s i -

The e r r o r

propagation for

Entry

Leaf

the

variables

as t h e n e x t e x a m p l e shows.

NoEntry :

in Nat

the opns-part)

~e~ec P a r a m e t r i c B i n a r y T r e e s = parm s o r t s

dis-

The s o r t

The f u n c t i o n s

t h e o~pD_s-part).

pure error

specifications,

one

Succ may a l s o be a p p l i e d

t h e axiom Times(O,n+)

constructors

n-

that

and s u b s o r t s a r e u s e d .

c a u s e an e r r o r

use

(I)

car-

makes no s t a t e m e n t a b o u t t h e n a t u r e o f

Three d i f f e r e n t

an ok v a r i a b l e

fied

Nat-Error

an ok v a l u e when a p p l i e d t o

The

would

an a l g e b r a h a v i n g as

T h e r e a r e some p e c u l i a r i t i e s

above w o r t h t o

that

result.

is

t h e s u b s o r t s N a t - O k and N a t - E r r o r .

is

assures

the specification

in

Suet.

parametric

84 Node :

Tree-Ok Tree-Ok - > Tree-Ok

NoTree : - > T r e e - E r r o r Leaf : E n t r y -> Tree Node : T r e e T r e e - > T r e e GetEntry :

Tree -> Entry

GetRight, GetLeft :

Tree -> Tree

vare

e+:Entry-Ok e-:Entry-Error

e_~ns

Leaf(e-)

t:Tree

tl+,t2+:Tree-Ok

= NoTree

N o d e ( N o T r e e , t > = N o d e ( t , N o T r e e ) = NoTree G e t E n t r y ( L e a f ( e + ) ) = e+ G e t E n t r y ( N o d e ( t l + , t 2 + > ) = NoEntry G e t E n t r y ( N o T r e e ) = NoEntry GetRight(Leaf(e+)) = GetLeft(Leaf(e+)) GetRight(Node(tl+,t2+))

= NoTree

= GetLeft(Node(t2+,tl+))

= t2+

G e t R i g h t ( N o T r e e ) = G e t L e f t ( N o T r e e ) = NoTree end spec The

specification

leaves sists

when it in

function t h e use o f If

is

builds

binary trees with given entries

applied.

the resulting GetEntry is the error

The g i v e n p a r a m e t e r s o r t

specification,

well

defined.

variable

e-

struction

the

T h i s can o n l y be a c h i e v e d by

in

would n o t be p e r s i s t e n t

per-

because

t h e axiom L e a f ( e - )

one would s p e c i f y o n l y L e a f ( N o E n t r y ) = N o T r e e ,

more e x c e p t i o n s t h a n t h e s i n g l e of

especially

the

at

Entry

for

error

=

NoTree.

then the con-

parameter algebras NoEntry.

Again,

having

lines

i-3

t h e 9 ~ D ~ - p a r t can be c o n s i d e r e d as t h e s i g n a t u r e s p e c i f i c a t i o n

for

t h e c o n s t r u c t o r s and l i n e s

ideas

4-7 f o r

the derived functions.

s k e t c h e d above a r e now made p r e c i s e i n

the (ollowing

The

chap-

ters.

3.

REVIEW OF ALGEBRAIC SPECIFICATIONS WITH SUBSORTS

The facts

following

remarks

r e v i e w the fundamental

and o u r n o t a t i o n c o n c e r n i n g a l g e b r a i c

subsorts.

Readers

etc.]

find

will

~amilar with

[Go 78,

many common d e t a i l s .

definitions

and

speci÷ications

Go 83,

Po 84,

and

SM 84,

85 3.1De÷inition A

signature

partial

(S,~,E)

c o n s i s t s of

(1) a s e t S of

sorts,

(2)

a

o r d e r ~ on S and (3) a f a m i l y Z=w~S* ssS of Bets of

function ~:v->r.

(Signature~ Algebra~ Morphism)

symbols Name(E)

such

that

(4) ~:w->s,

v~w

and

r~s

implies

= {~w'sl~eEw~s} denotes t h e f u n c t i o n names and

Symb(Z) = {~Id~Zw, s} the f u n c t i o n symbols of Z. A E - a l g e b r a (A,F) c o n s i s t s of that

(1) a f a m i l y A=s~S of s e t s such

(2) s~r i m p l i e s Asia r and (3) a f a m i l y F-< _ ~A w , s>~W'SsName(Z)

of f u n c t i o n s w i t h ~ ' S : A w - > As such that~

(4) i f

~:w->s,

~:v->r

and a~AwnAv, then ~ ' s ( a ) --~A v'r(a) A

Z-morphism

s~S

of

f:A->B

mappings such t h a t

a~Aw and (2) a~AsnAt

3.2 D e f i n i t i o n The

E-term

seS

of

s1...sn->s

between

E - a l g e b r a s A and B (i)

algebra

and

(I)

least

family

the for

d

:

functions ~:->s

and

f o r ~ : s l . . . s n - > s and t i E T s i .

of the term a l g e b r a )

E-term a l g e b r a TZ i s i n i t i a l

i n t h e c a t e g o r y ALGZ of a l l

E-

Z-morphisms between them.

(Congruence, Q u o t i e n t ) s on a E - a l g e b r a A i s a f a m i l y seS of

t i o n s ~s on As such t h a t implies

for

d : - > s i m p l i e s ~ T s and (2)

are determined by (3) ~ , s : = ~

(Initiality

Z-congruence

the

t i ~ T s i i m p l i e s d ( t l . . . t n ) ~ T s and

algebras with a l l

A

fs(~'S(a))=~'S(fw(a))

(Tz,F Z) has as c a r r i e r s

sets s a t i s f y i n g

3.4 D e f i n i t i o n

family

implies fs(a)=ft(a).

(4) ~ ? 1 " ' ' s n ' s ( t l . . . t n ) : = ~ ( t l . o . t n )

The

a

(Term a l g e b r a )

K~'S>dw,SEName(Z)

3.3 Fact

is

rela-

(1) ~s = [~EQ n AsXAs ] and (2) ai ~EQ bi

~ l"''sn's(al"''an)

~EQ ~ i ' ' ' u n ' r ( b l " ' ' b n )

for alibi

E

AsinAui ,

d : s l . . . s n - > s and d : u 1 . . . u n - > r , where ~EQ i s the e q u i v a u lence on sasAs generated by ~.

The q u o t i e nt A/~ of a E - a l g e b r a A by a E-congruence ~ has (1) the c a r r i e r s A/E s = { [ a ] l a e A s } ~ the

where [ a ] = { b ~ U-A la~-~b}

f u n c t i o n s ~w,S~Name(Z)

[~l'''sn's(bl...bn)],

and

(2)

sl"''sn,s([al]...Zan]):= w i t h ~A/~

where [ a i ] ~ A / ~ s i ~ [ a i ] = [ b i ]

and b i ~ A s i .

86 3.5 D e f i n i t i o n

(Equation~ S a t i s f a c t i o n ,

A

L=R i s a p a i r o f

~zeguation

signature Z Z-algebra cide.

Z(V)-terms,

having a d d i t i o n a l l y

A satisfies

A specification

L=R~ (Z,E)

Specification)

if

where

Z(V)

is

the

t h e v a r i a b l e s V as c o n s t a n t s . all

e v a l u a t i o n s o f L and R

A

coin-

c o n s i s t s o f a s i g n a t u r e Z and a s e t E

of E - e q u a t i o n s .

3 . 6 Fact A

(Induced Congruence)

s e t of E - e q u a t i o n s E i n d u c e s u n i q u e l y a s e t o f c o n s t a n t

tions

E(Tz) ,

which

a g a i n i n d u c e s a l e a s t congruence ~E

equaon

TZ

c o n t a i n i n g E(Tz)°

3 . 7 Fact

(Initiality

of

t h e q u o t i e n t term a l g e b r a )

The q u o t i e n t term a l g e b r a TZ/E E i s of a l l

(Z,E)-algebras satisfying

3 . 8 Example ( B i t s t r i n g s The

h a v i n g as s u b s o r t s

and s i n g l e b i t s

i n t h e c a t e g o r y ALGz, E

t h e e q u a t i o n s E.

handling)

error

following lines define bitstrings

String*)

~

avoiding

initial

of

arbitrary

non empty b i t s t r i n g s

length

(sort

( s o r t S t r i n g +)

(sort Bit).

B i t S t r i n g s A v o i d i n g E r r o r H a n d l i n g= sorts Bit

< String+ < String*

opns

: -> B i t

0,1

: -> S t r i n g

.

.l.

: S t r i n g * S t r i n g * -> S t r i n g *

.I.

: Bit

.l.

: String* Bit

First,

S t r i n g * -> S t r i n g + -> S t r i n g +

L a s t : S t r i n g + -> B i t

vats

b:Bit

e~ns

s l l ( s 2 1 s 3 ) = ( s l l s 2 ) Is3

e,sl~s2,s3:String*

sl~ = his = s First(bls)

= Last(slb)

= b

end spec Please

note

t h a t the s p e c i f i c a t i o n

s o r t s and v a t s has n o t r e a l l y determines

p a r t between t h e

t o be a s i g n a t u r e ,

but i t

a s i g n a t u r e i n t h e sense o f our d e f i n i t i o n .

more t h e f u n c t i o n s F i r s t

key

and L a s t r e t u r n i n g t h e f i r s t

words

uniquely Further-

respective-

87 ly

last

cally

bit

are well

defined,

because a l l

a l l o w e d by t h e s i g n a t u r e e i t h e r

applications syntacti-

yield

0 or

1.

3 . 9 Remark ( D e c l a r a t i o n s ) One can a l s o use so c a l l e d d e c l a r a t i o n s i n s p e c i f i c a t i o n s Go

83].

A d e c l a r a t i o n c o n s i s t s of

that

the

term w i l l

sort

(e.g.

a term and a

sort,

a l w a y s e v a l u a t e t o an element o f

i * i : N o n N e g a t i v e ~ where i

is

a v a r i a b l e of

[Go 787 assuring

the sort

given int).

4. CLEAN SPECIFICATIONS

4.1 D e f i n i t i o n A

signature

(Clean, o k / e r r o r - c o n s i s t e n t , (S,~,Z)

S-OKuS-ERROR,

is called

ok/error-complete)

(ok/error-)clean,

S-OK={s-OklsES-MAIN},

if

S=S-MAINu

S-ERROR={s-Error~sES-MAIN}

and ~ = { s ~ s l s s S } u { s - O k ~ s , s - E r r o r ~ s l s s S - M A I N } . A Z - a l g e b r a A w i t h Z a

clean s i g n a t u r e i s c a l l e d

As_Error and (3) A

= 0,

A is

specification is

ok~error-consistent,

(2~ o k / e r r o r - c o m p l e t e ,

clean, if

algebra

(I)

A

eeE(T~) i m p l i e s e i t h e r s u i t a b l e s o r t s.

As_Ok n

As_ok u As_Error

=

As,

o k / e r r o r - c o n s i s t e n t and o k / e r r o r - c o m p l e t e .

(Z,E)

clean.

if

if

is

called clean,

if

the

s e t E of e q u a t i o n s i s

initial

called

(E,E)-

clean,

eeTs_okXTs_Ok o r eeTs_ErrorXTs_Error

ALGz,E,CLEA N d e n o t e s t h e c a t e g o r y o f

(Z,E)-algebras with all

all

if

for

a

clean

morphisms between them.

4 . 2 C h a r a c t e r i s a t i o n ( S p e c i f i c a t i o n s w i t h c l e a n term a l g e b r a s ) Given the

a specification specification

(Z,E)

(~,E)

is

w i t h a c l e a n term a l g e b r a clean,

if

and o n l y i f

TE,

then

the set E

of

equations is clean.

4 . 3 C h a r a c t e r i s a t i o n (Clean s p e c i f i c a t i o n s ) A specification (I)

T~, E i s

(2)

there is

(E,E)

is clean, if

and o n l y i f

o k / e r r o r - c o n s i s t e n t and a subspecification

(a) ZG c o n t a i n i n g a l l ok o r e r r o r

result

(b) EG c o n t a i n i n g a l l

(ZG,EG)~(Z~E)

s o r t s and s u b s o r t s and s o r t s and c l e a n e q u a t i o n s o f E and

with all

operations with

88 (c)

there is

a unique s u r j e c t i v e

morphism f:~G,EG->U~_>EG(T%,E ) .

4 . 4 Remark ( S u r j e c t i v e morphiem i n If

t h e morphism f

of

(~B,EG)

then t h e r e a r e terms t l

that

TZG,EG ~ [ t l ] ~ [ t 2 ]

maximal s e t o f additional ok

is also injective,

above) then

(Z,E)

i s an e n r i c h m e n t

: T~G,ES and U~_>EB(T~, E) a r e i s o m o r p h i c . I f

injective, such

(c)

:

identification

and TZ, E ~ [ t l ] = [ t 2 ] .

in

t3eTs-(Ts_okUTs_Error), can

also

tl=t3

be done c h o o s i n g

involving

o n l y ok o r e r r o r t e r m s . this

establish

not

error

But EG i s

T~, E i s done v i a a term t 3

rule

out

is

a

e q u a t i o n s a p p l i c a b l e t o ok and e r r o r t e r m s , so t h e

identification

nor e r r o r

it

and t 2 b o t h ok o r b o t h

It

is

and

t3=t2.

different

a l s o much

neither

equations

smoother

case from a m e t h o d o l o g i c a l p o i n t o f view

a clear distinction

between ok and e r r o r

This

and

to to

constructors

and d e r i v e d f u n c t i o n s .

4 . 5 Concept ( P r a g m a t i c s f o r A

clean

specification

clean s p e c i f i c a t i o n s )

(Z,E)

should

(ZG,EG) w i t h T~B and EG c l e a n such t h a t

have

a

subspecification

(Z,E)

is

an e n r i c h m e n t o f

(ZG,EG).

4 . 6 Example ( B i t s t r i n g s This

with error handling)

clean s p e c i f i c a t i o n

defines bitstrings

of

arbitrary

E r r o r s a r e i n t r o d u c e d by t h e f u n c t i o n s Head and T a i l t o t h e empty s t r i n g . BitStrings = sorts Bit, cons

0,1

String : -> B i t - O k

NoHead : -> B i t - E r r o r : -> S t r i n g - O k • t.

: S t r i n g - O k B i t - O k -> S t r i n g - O k

NoTail : -> S t r i n g - E r r o r runes . I .

: String Bit

-> S t r i n g

Head : S t r i n g - > B i t Tail

: S t r i n g -> S t r i n g

vats

s:String s+:String-Ok b:Bit

eqns

N o T a i l l b = sINoHead = N o T a i l

length.

when a p p l i e d

b+,b1+,b2+:Bit-Ok

89 H e a d ( s + I b l + I b 2 + ) = He~d(s+Ib1+) Head(~ib+) = b+ Head(~) = Head(NoTail) = NoHead Tail(s+Ibl+lb2+) = Tail(s+Ibl+)ib2+ Tail(~Ib+) = T a i l ( ~ ) = T a i l ( N o T a i l ) = NoTail end spec The

p a r t s f o r t h e ok and e r r o r = o n s t r u c t o r s and f o r t h e

functions general

are

indicated

there will

by t h e keywords cons

be an e q u a t i o n p a r t f o r t h e

and

derived

funcs.

In

constructors

as

w e l l . For t h e s u b s o r t s t h e f o l l o w i n g e q u a t i o n s h o l d : T~,E,Bit_Ok ~{0,1},

T E , E , B i t _ E r r o r ~ { N o H e a d } v TE,E,String_Ok ~ ( { 0 ~ i } ) *

and

T E , E , S t r i n g _ E r r o r ~ { N o T a i l } . On t h i s b a s i s t h e f u n c t i o n s Head and T a i l a r e d e f i n e d such t h a t t h e s u b s o r t s a r e r e s p e c t e d .

5. CLEAN PARAMETRIC SPECIFICATIONS

5.1 D e f i n i t i o n A

( S i g n a t u r e morphism, s p e c i f i c a t i o n morphism)

s i g n a t u r e morphism f : Z 1 - > Z 2 between s i g n a t u r e s ( S I , ~ $ I , [ 1 ) and

($2,~$2,E2) Symb(E2)

consists

implies

forgetful

mappings

f:SI->S2

such t h a t s ~ S l r i m p l i e s f ( s ) ~ s 2 f ( r )

f ( ~ ) e £ 2 f ( w ) , f ( s ). s

s i g n a t u r e morphism f

c a l l e d s p e c i f i c a t i o n morphism from (Z1,EI) t o

specification

and

(E2,E2),

if

f

a is

every

b e l o n g s t o E2 : f ( E I ) ~ E 2 . A

i s c a l l e d simple,

if

$1~$2,

Symb(El)~

Symb(E2) and f : S I - > S 2 and f:Symb(El)->Symb(E2) a r e i n c l u s i o n s .

5.2 D e f i n i t i o n A

(Parametric s p e c i f i c a t i o n ~ p e r s i s t e n t )

p a r a m e t r i c s p e c i f i c a t i o n c o n e i s t s of a p a r a m e t e r s p e c i f i c a t i o n

{ZP,EP) EP~EB.

and The

a body s p e c i f i c a t i o n

(ZB~EB) such

c o n s t r u c t i o n F:ALGzp,Ep->ALGEB~EB [ADJ 78, specification rally"

that

EP~ZB and

semantics of a p a r a m e t r i c s p e c i f i c a t i o n i s t h e

is called persistent~

[WE 85] i s o m o r p h i c f o r

all

if

Po 8 4 ] .

free

A parametric

A and U(F(A)) a r e " n a t u -

(ZP~EP)-algebras A,

where U i s

90 the f o r g e t f u l

f u n c t o r U:ALGEB->ALGzp induced by t h e s i g n a t u r e s EP

and EB.

5.3 D e f i n i t i o n The

( A p p l i c a t i o n of a p a r a m e t r i c s p e c i f i c a t i o n )

r e s u l t of a p p l y i n g a p a r a m e t r i c s p e c i f i c a t i o n w i t h parameter

(ZP,EP) means

and body (~B,EB) of

a

t o an a c t u a l s p e c i f i c a t i o n

s p e c i f i c a t i o n morphism

specification

(~R,ER),

IF ssSP THEN h(s)

(ZA,EA)

h:(~P,EP)->(~A~EA)

is

by the

where ER=EA+hR(EB), ER=EA+hR(EB), hR(s) =

ELSE s FI

and hR(d) = IF ~sSymb(EP) THEN h(~)

ELSE d F I . (ZP~EP) . . . . ~ - - - >

(EB~EB)

I I h

I I

I

I hR

I

I

(ZA,EA) The

sR

> (ER~ER)

r e s u l t s p e c i f i c a t i o n i s t h e pushout of t h e a c t u a l s p e c i f i c a -

tion the

(ZA~EA) and t h e body s p e c i f i c a t i o n

(ZB~EB) w i t h r e s p e c t

parameter (EP,EP) and t h e s p e c i f i c a t i o n morphisms h

where

s

is

t h e s i m p l e s p e c i f i c a t i o n morphiem

induced

and by

to s, the

i n c l u s i o n of t h e parameter i n t h e body.

5.4 D e f i n i t i o n

(Clean p a r a m e t r i c s p e c i f i c a t i o n )

A

specification

parametric

(ZB,EB) the free

is called clean,

if

with

parameter

(EP~EP) and

f r e e c o n s t r u c t i o n F i s p e r s i s t e n t on ALBEp~EP~CLEAN and construction

i m p l i e s F(A)

body

t h e s i g n a t u r e s ZP and ZB a r e c l e a n ,

F p r e s e r v e s cleanness :

A

~

the

ALSEp,EP,CLEAN

E ALGEB,EB,CLEAN.

5 . 5 E x t e n s i o n Lemma ( f o r c l e a n p a r a m e t r i c s p e c i f i c a t i o n s ) Let

t h e r e be g i v e n a c l e a n p a r a m e t r i c s p e c i f i c a t i o n w i t h parame-

ter

(EP~EP) and body (~B,EB)~

(EA,EA)~

a

strict

actual

clean

specification

s p e c i f i c a t i o n morphism h: (EP~EP)->(EA~EA) and

the r e s u l t s p e c i f i c a t i o n (I)

an

(ER,ER) as d e f i n e d above.

The r e s u l t i n g p a r a m e t r i c s p e c i f i c a t i o n w i t h p a r a m e t e r (EA,EA) and body (ZR,ER) i s c l e a n : FR i s p e r s i s t e n t on ALGEA,EA~CLEAN and i t

preserves cleanness.

91 (2) F o Uh = UhR o FR. . . . . E___> ALG~p,EP,CLEAN ALGZB,EB,CLEAN

t

I

l

Uh ;

i UhR

l i

i I

ALGEA,EA,CLEAN . . . . ~ - - >

ALG~R,ER,CLEAN

5 . 6 Remark ( c o n c e r n i n g t h e e x t e n s i o n lemma) The p r o o f o f [Eh

81].

our e x t e n s i o n lemma a p p l i e s t h e R - e x t e n s i o n lemma o f

The

restriction

of ALBzp,EP t o c l e a n a l g e b r a s can

e x p r e s s e d as p r e d i c a t e f o r m u l a r e q u i r e m e n t s . clean

algebras

method,

because

neither

ok

morphism

the

underlying

The s t r i c t n e s s

o f t h e parameter

i m p l i e s t h a t ok o r e r r o r o p e r a t i o n s will

also

be ok o r e r r o r o p e r a t i o n s

to

specification

one does n o t want t o c a r e a b o u t e l e m e n t s

nor e r r o r .

h

parameter

is essential for

This r e s t r i c t i o n

be

being

passing

of

the

formal

in

the

actual

parameter.

5 . 7 Concept

(Pragmatics f o r

Analogously

to

clean parametric s p e c i f i c a t i o n s )

t h e case w i t h o u t p a r a m e t e r s a c l e a r

distinction

between ok and e r r o r c o n s t r u c t o r s and d e r i v e d f u n c t i o n s s h o u l d be established.

Therefore

parameter (ZP,EP) (ZP,EP)

a

clean parametric

~ (ZB,EG) ~ (ZB,EB)

all

w i t h T~G(A) and EG c l e a n such t h a t G

A~ALGEp,EP,CLEAN,

where G i s

duced by t h e p a r a m e t r i c s p e c i f i c a t i o n body

is

an e n r i c h m e n t o f B(A)

the f r e e c o n s t r u c t i o n w i t h p a r a m e t e r (EP,EP)

inand

(ZG,EG).

5 . 8 Example ( P a r a m e t r i c s t r i n g s

with error handling)

This clean parametric s p e c i f i c a t i o n trary

with

and body (ZB~EB) s h o u l d have a s u b s p e c i f i c a t i o n

i s p e r s i s t e n t on ALGzp,EP,CLEAN and F(A) for

specification

parameter

s o r t Char.

f u n c t i o n s Head and T a i l

o v e r an a r b i -

Again e r r o r s a r e i n t r o d u c e d by

when a p p l i e d t o t h e empty s t r i n g .

s pec P a r a m e t r i c S t r i n g s = parm s o r t s Char o~ons

defines strings

NoHead : -> C h a r - E r r o r

the

92 bod~ s o r t s S t r i n g cons

A : -> S t r i n g - O k .I.

: S t r i n g - O k Char-Ok -> S t r i n g - O k

NoTail : -> S t r i n g - E r r o r funcs

.I.

: S t r i n g Char - > S t r i n g

Head : S t r i n g -> Char Tail vats

: S t r i n g -> S t r i n g

s:String

s+:String-Ok

c:Char c + ~ c l + , c 2 + : C h a r - O k t - : C h a r - E r r o r eqns

NoTaillc = slc-

= NoTail

Head(s+Icl+Ic2+) = Head(s+Icl+) Head(Ale+) = c+ Head(A) = H e a d ( N o T a i l ) = NoHead Tail(s+Icl+Ic2+)

= Tail(s+Icl+)Ic2+

Tail(AIc+) = A Tail(A)

= T a i l ( N o T a i l ) = NoTail

e n d sp,ec The

parts

keywords for

the

it

is

for

the

parameter

p a r m and b o d ~ , parameter

and t h e

essential for

Char-Error algebra

In

and t h e

general

body are

there

constructors

will

indicated

be an e q u a t i o n

as w e l l .

= NoTail.

algebra

F(A)Char_Ok

F(A)

will

have

the

the part that sort

parameter

given~

following

note

c - of

I÷ a c l e a n

A w i t h s e t s AChar_Ok and AChar_Error i s

resulting

Please

p e r s i s t e n c y t o use t h e v a r i a b l e

in the equation s l c -

by

then t h e

carriers

:

~

AChar_Ok, F(A)Char-Error ~ AChar_Error , )* F ( A ) s t r i n g _ Ok ~ (AChar_Ok and F ( A ) s t r i n g _ E r r o r ~ { N o T a i l } . F u r t h e r m o r e t h e c o r r e s p o n d i n g f r e e c o n s t r u c t i o n i s n o t p e r s i s t e n t on ALG~p,Ep,

if

no r e s t r i c t i o n

t o c l e a n a l g e b r a s i s made.

5 . 9 Remark ( P o i n t e d a l g e b r a s and s p e c i f i c a t i o n s ) All

c o n s i d e r a t i o n s p r e s e n t e d here can be s p e c i a l i z e d t o

a l g e b r a s [Go 8 6 ] , sort.

In t h i s

pointed

where t h e r e i s o n l y one e r r o r element f o r

case e r r o r r e c o v e r y i s n o t s u p p o r t e d t o o w e l l ,

e s p e c i a l l y e r r o r p r o p a g a t i o n can be done a u t o m a t i c a l l y .

each but

93 6.

CONCLUSION

The

notion

algebra

of

a

clean algebra i s

satisfying

certain

a special

case

of

s o r t e q u a t i o n s which e s p e c i a l l y

sense i n t h e c o n t e x t o f p a r t i a l l y considered

just

an make

o r d e r e d s o r t s and which can

as a n o t h e r c o n s t r u c t f o r

algebraic specification

guages. For example i n c l e a n a l g e b r a s t h e s o r t

be lan-

equations

s-Ok n ~ - E r r o r = ~ and s-Ok u s - E r r o r = s are v a l i d f o r sort like

all

s o r t s s.

terms b u i l t union,

over the g i v e n s e t of

intersection,

An a l g e b r a s a t i s f i e s u a t i o n s of

A s o r t equation c o n s i s t s of a p a i r of s o r t s and s e t

operations

d i f f e r e n c e ~ complement and empty s e t .

a sort equation,

if

the set theoretic eval-

t h e two e x p r e s s i o n s w i t h r e s p e c t t o t h e g i v e n

coincide. This t o p i c

is

algebra

subject to f u t u r e research.

7. REFERENCES

ADJ 76

J.A.Goguen/3.W.Thatcher/E.S.Wagner : approach t o t h e s p e c i f i c a t i o n , tation

of a b s t r a c t data types.

gramming Hall, ADJ 78

methodology,

Englewood C l i f f s

H. E h r i g

/

R.T.yeh (ed),

tion

:

lOth STOC~ 1978,

/

1982,

C.Choppy :

tions. BGP 82

Proc.

F.Boisson / L.R.I.

/

pp.322-369.

Abstract

r e c o v e r y by means o f llth

ICALP 1984,

types

of

To a p p e a r .

exception handling

e q u a t i o n s and

declara-

LNCS 172, p p . 9 5 - 1 0 9 .

G. Guiho / D.Pavot :

R e p o r t , Orsay 1982.

data

approach based on a

between e x c e p t i o n s and e r r o r s .

M.Bidoit : Algebraic specification error

E.G. Wagner

Parameter p a s s i n g i n a l g e b r a i c s p e c i f i c a -

B . B e r n o t / M. B i d o i t

and

specification

San Diego.

w i t h e x c e p t i o n h a n d l i n g : An i n i t i a l

Bi 84

Prentice

Data t y p e s p e c i f i -

3~W.T h a t c h e r /

languages. LNCS 134, B e r l i n

distinction

pro-

i978~ p p . 8 0 - 1 4 9 .

H.-J.Kreowski /

J.B.Wright

BBC 8b

V o l . IV~

P a r a m e t r i z a t i o n and t h e power o f

t e c h n i q u e s . Proc.

algebra

Current trends in

J.W.Thatcher/E.S.Wagner/~.B.Wright : cation :

ADJ 81

An i n i t i a l

c o r r e c t n e s s and implemen-

Multioperator algebras.

94 Eh 81

H.Ehrig

:

A l g e b r a i c t h e o r y of parametrized

specifica-

t i o n s w i t h r e q u i r e m e n t s . Proc. b t h CAAP 1981, 8enova. EFH 83

H. Ehrig/W.Fey/H.Hansen : ACT ONE : An a l g e b r a i c s p e c i f i cation

language w i t h two l e v e l s

Report No. 8 3 - 0 3 , TU B e r l i n , EKMP 82

of

semantics.

Techn.

1983.

H. E h r i g / H . - J . K r e o w e k i / B . M a h r / PPadawitz . :

A l g e b r a i c im-

p l e m e n t a t i o n o f a b s t r a c t d a t a t y p e s . TCS, V o l . 2 0 1982. FGJM 85

K°Futasugi / J.A.Goguen /

J . - P . Jo u a n n a u d / J.Meseguer :

P r i n c i p l e s o f OBJ2. Proc. POPL 1985, p p . 5 2 - 6 6 . Ga 83

H.Ganzinger

:

Parametrized s p e c i f i c a t i o n

:

Parameter

passing and i m p l e m e n t a t i o n . ACM TOPLAS, V o l . 5 1983. GSM 76

V . G i a r r a t a n a / F . O i m o n a / U . M o n t a n a r i: cepts

in a b s t r a c t data type

Observability

specification.

Proc.

con5th

MFCS 1976, Gdansk, LNCS 45. SDLE 82

M . G o g o l l a / K . D r o s t e n / U . L i p e c k / H . - D . E h r i c h : A l g e b r a i c and operational

semantics o f s p e c i f i c a t i o n s a l l o w i n g e x c e p -

t i o n s and e r r o r s . TCS, V o i . 3 4 1984, pp.289-313. Go 83

M. G o g o l l a

:

specifications. cells Go 86

Partially

ordered

sorts

in

algebraic

Proc. 9 t h CAAP 1984, Bordeaux, B. Cour-

( e d ) , Cambridge U n i v e r s i t y Press, pp.139-153.

M.Gogolla : Ober p a r t i e l l

g e o r d n e t e Sortenmengen und d e -

t e n Anwendung z u r F e h l e r b e h a n d l u n g i n A b s t r a k t e n

Daten-

t y p e n . D i s s e r t a t i o n , TU Braunschweig, 1986. 8o 77

J.A.Goguen Proc.

:

Abstract e r r o r s f o r a b s t r a c t data

Conference

on Formal D e s c r i p t i o n o~

types.

Programming

Concepts 1978, E . J . N e u h o l d ( e d ) , North H o l l a n d . 8o 78

J.A.Goguen : Order s o r t e d a l g e b r a s : E~ception and e r r o r s o r t s , c o e r c i o n s and o v e r l o a d e d o p e r a t o r s . Semantics and Theory of Computation Report No.14, UCLA, 1978.

SM 84

J.A.Goguen/J.Meseguer : Order-sorted a l g e b r a I : P a r t i a l and o v e r l o a d e d o p e r a t o r s ,

e r r o r s and i n h e r i t a n c e . Tech-

n i c a l R e p o r t , SRI I n t e r n a t i o n a l , GJM 85

K1 84

1984.

J.A. Goguen/J.-P.Jouannaud/J.Meseguer :

Operational

m a n t i c s f o r o r d e r - s o r t e d a l g e b r a . Proc.

12th ICALP 1985.

se-

H . K l a e r e n : A c o n s t r u c t i v e method f o r a b s t r a c t a l g e b r a i c software specification.

TCS, V o l . 3 0 , No.2 1984.

95 Po 84

A.Poigne

:

Modularization

specifications ST 85

with subsorts.

D.Sannella/M.Wirsing : specification

Wa 79

M.Wand : sions.

WE 85

for

algebraic

I m p e r i a l C o l l e g e , London.

D . S a n n e l l a / A ~ T a r l e c k i : On o b s e r v a t i o n a l e q u i v a l e n c e and algebraic specification.

SW 83

techniques

l O t h CAAP 1985, B e r l i n .

kernel language f o r

Final

a l g e b r a s e m a n t i c s and d a t a t y p e

~CSS, V o l ~ l g ,

data types.

exten-

No. 1 1979, p p . 2 7 - 4 4 . Canonical constraints

for

parame-

Research R e p o r t RC 11248, IBM, 1985.

WPPDB 83 M . W i r s i n g / P . P e p p e r / H . Partsch/W. Dosch/M.Broy : a r c h i e s of

algebraic

and i m p l e m e n t a t i o n . P r o c . FCT 1983.

E.G.Wagner/H.Ehrig : trized

Proc. A

abstract data types.

On

hier-

A c t a I n f o r m a t i c a 1983~

Suggest Documents