S u p p o r t i n g S u p p o r t i n g C o v - - PowerPoint PPT Presentation

s u p p o r t i n g s u p p o r t i n g c o v a r i a n t
SMART_READER_LITE
LIVE PREVIEW

S u p p o r t i n g S u p p o r t i n g C o v - - PowerPoint PPT Presentation

S u p p o r t i n g S u p p o r t i n g C o v a r i a n t R e t u r n T y p e s C o v a r i a n t R e t u r n T y p e s & G e n e r i c s & G e n e r i c s i n i


slide-1
SLIDE 1

S u p p

  • r

t i n g S u p p

  • r

t i n g C

  • v

a r i a n t R e t u r n T y p e s C

  • v

a r i a n t R e t u r n T y p e s & G e n e r i c s & G e n e r i c s i n i n T y p e R e l a x e d We a v i n g T y p e R e l a x e d We a v i n g

T

  • mo

y u k i A

  • t

a n i T

  • mo

y u k i A

  • t

a n i J a p a n A d v a n c e d I n s t i t u t e

  • f

S c i e n c e a n d T e c h n

  • l
  • g

y J a p a n A d v a n c e d I n s t i t u t e

  • f

S c i e n c e a n d T e c h n

  • l
  • g

y J

  • i

n t w

  • r

k w / J

  • i

n t w

  • r

k w / H i d e h i k

  • Ma

s u h a r a & Ma n a b u T

  • y

a ma H i d e h i k

  • Ma

s u h a r a & Ma n a b u T

  • y

a ma U n i v e r s i t y

  • f

T

  • k

y

  • U

n i v e r s i t y

  • f

T

  • k

y

slide-2
SLIDE 2

B a c k g r

  • u

n d : B a c k g r

  • u

n d : A s p e c t J , R e l a x A J a n d G e n t l e A J A s p e c t J , R e l a x A J a n d G e n t l e A J

+ T y p e r e l a x e d w e a v i n g

[ Ma s u h a r a 1 ]

+ S u p p

  • r

t f

  • r

* G e n e r i c s * C

  • v

a r i a n t r e t u r n t y p e s * proceed > mu l t i p l e r e t u r n t y p e s > a r g u me n t t y p e r e l a x a t i

  • n

G e n t l e A J R e l a x A J

[ Ma s u h a r a 1 ]

A s p e c t J

slide-3
SLIDE 3

B a c k g r

  • u

n d : B a c k g r

  • u

n d : A s p e c t J , R e l a x A J a n d G e n t l e A J A s p e c t J , R e l a x A J a n d G e n t l e A J

+ T y p e r e l a x e d w e a v i n g

[ Ma s u h a r a 1 ]

+ S u p p

  • r

t f

  • r

* G e n e r i c s * C

  • v

a r i a n t r e t u r n t y p e s

* proceed > mu l t i p l e r e t u r n t y p e s > a r g u me n t t y p e r e l a x a t i

  • n

G e n t l e A J R e l a x A J

[ Ma s u h a r a 1 ]

A s p e c t J

slide-4
SLIDE 4

T y p e r e l a x e d w e a v i n g ( T R W) T y p e r e l a x e d w e a v i n g ( T R W)

[ Ma s u h a r a 1 ] [ Ma s u h a r a 1 ]

: : D i f f e r e n c e f r

  • m

A s p e c t J ' s w e a v i n g D i f f e r e n c e f r

  • m

A s p e c t J ' s w e a v i n g

Int around():call(BigInt *.*(...)){...} Int around():call(Object *.*(...)){...}

  • S

u p p

  • s

e w e h a v e

  • A

s p e c t J a n d R e l a x A J ( = T R W) a c c e p t

  • R

e l a x A J c

  • n

d i t i

  • n

a l l y a c c e p t b u t A s p e c t J r e j e c t s

class Object{...} class BigInt extends Object{...} class Int extends Object{...} s u p e r t y p e s i b l i n g

slide-5
SLIDE 5

T y p e r e l a x e d w e a v i n g T y p e r e l a x e d w e a v i n g

[ Ma s u h a r a 1 ] [ Ma s u h a r a 1 ]

  • B

y t e c

  • d

e

  • l

e v e l w e a v i n g

  • T

y p i n g p r i n c i p l e f

  • r

w e a v i n g a d v i c e :

– jp:

a j

  • i

n p

  • i

n t

– adv:

a p i e c e

  • f

a r

  • u

n d a d v i c e a p p l i e d t

  • jp

P r i n c i p l e .

T h e r e t u r n t y p e

  • f

adv mu s t b e c

  • n

s i s t e n t w i t h t h e

  • p

e r a t i

  • n

s t h a t u s e t h e r e t u r n v a l u e f r

  • m

jp.

a me t h

  • d

T around(): p(){...} adv jp a p p l i e d u s e a s T1 u s e a s T2 u s e a s T3 T mu s t b e a s u b t y p e

  • f

T1, T2 a n d T3

slide-6
SLIDE 6

T y p e r e l a x e d w e a v i n g : T y p e r e l a x e d w e a v i n g :

  • p

e r a t i

  • n

s t h a t

  • p

e r a t i

  • n

s t h a t u s e u s e t h e r e t u r n v a l u e t h e r e t u r n v a l u e

  • I

n v

  • k

i n g a me t h

  • d

:

  • .m(a)

– R

e c e i v e r : u s e t y p e i s t h e mo s t g e n e r a l t y p e t h a t d e f i n e s m

– A

r g u me n t : u s e t y p e i s t h e t y p e a p p e a r i n t h e s i g n a t u r e

  • R

e t u r n n i n g f r

  • m

t h e me t h

  • d

: return v

  • A

c c e s s i n g a f i e l d :

  • .

f = v

  • T

h r

  • w

i n g a n e x c e p t i

  • n

: throw v

  • A

c c e s s i n g a n a r r a y : a[i]=v

slide-7
SLIDE 7

E x a m p l e

  • f

R e l a x A J a d v i c e : E x a m p l e

  • f

R e l a x A J a d v i c e : R e p l a c i n g B i g I n t S t r e a m w / I n t S t r e a m R e p l a c i n g B i g I n t S t r e a m w / I n t S t r e a m

interface Stream{ Object get(); } class BigIntStream implements Stream{ Object get(){ /*return a BigInt*/ } } class IntStream implements Stream{ Object get(){ /*return an Int*/ } } bs = new BigIntStream();

  • = bs.get();

s = o.toString(); /* bs is no longer used*/ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k IntStream i s c

  • n

s i s t e n t w i t h Stream.get() invokevirtual BigIntStream.get() invokeinterface Stream.get()

S i b l i n g

  • f

BigIntStream A c c e p t e d t r u e

slide-8
SLIDE 8

T y p e r e l a x e d w e a v i n g T y p e r e l a x e d w e a v i n g

[ Ma s u h a r a 1 ] [ Ma s u h a r a 1 ]

  • B

y t e c

  • d

e w e a v i n g me c h a n i s m

  • T

y p i n g r u l e f

  • r

a r

  • u

n d a d v i c e :

– jp:

a j

  • i

n p

  • i

n t

– adv:

a p i e c e

  • f

a r

  • u

n d a d v i c e a p p l i e d t

  • jp
  • F
  • r

ma l mo d e l : b a s e d

  • n

F J

[ I g a r a s h i 1 ]

w / u n i

  • n

t y p e

  • S

u p p

  • r

t f

  • r

J a v a 5 f e a t u r e s i s n

  • t

c

  • n

s i d e r e d

– G

e n e r i c s a n d c

  • v

a r i a n t r e t u r n t y p e s

P r i n c i p l e .

T h e r e t u r n t y p e

  • f

adv mu s t b e c

  • n

s i s t e n t w i t h t h e

  • p

e r a t i

  • n

s t h a t u s e t h e r e t u r n v a l u e f r

  • m

jp.

slide-9
SLIDE 9

G

  • f
  • r

w a r d i n t

  • J

a v a 5 : G

  • f
  • r

w a r d i n t

  • J

a v a 5 : w h a t a r e n e e d e d ? w h a t a r e n e e d e d ?

  • S

u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s

– C

h a n g i n g t h e r e l a x a t i

  • n

r u l e f

  • r

s i g n a t u r e s

  • f

me t h

  • d

i n v

  • c

a t i

  • n

s

  • S

u p p

  • r

t f

  • r

g e n e r i c s

– I

n f e r r i n g e r a s e d t y p e s

We a r e a t b y t e c

  • d

e

  • l

e v e l !

slide-10
SLIDE 10

E x a m p l e

  • f

R e l a x A J a d v i c e : E x a m p l e

  • f

R e l a x A J a d v i c e : R e p l a c i n g B i g I n t S t r e a m w / I n t S t r e a m R e p l a c i n g B i g I n t S t r e a m w / I n t S t r e a m

interface Stream{ Object get(); } class BigIntStream implements Stream{ Object get(){ /*return a BigInt*/ } } class IntStream implements Stream{ Object get(){ /*return an Int*/ } } bs = new BigIntStream();

  • = bs.get();

s = o.toString(); /* bs is no longer used*/ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k IntStream i s c

  • n

s i s t e n t w i t h Stream.get() invokevirtual BigIntStream.get() invokeinterface Stream.get() t r u e

slide-11
SLIDE 11

G

  • f
  • r

w a r d i n t

  • J

a v a 5 : G

  • f
  • r

w a r d i n t

  • J

a v a 5 : w h a t a r e n e e d e d ? w h a t a r e n e e d e d ?

  • S

u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s

– C

h a n g i n g t h e r e l a x a t i

  • n

r u l e f

  • r

s i g n a t u r e s

  • f

me t h

  • d

i n v

  • c

a t i

  • n

s

  • S

u p p

  • r

t f

  • r

g e n e r i c s

– I

n f e r r i n g e r a s e d t y p e s

slide-12
SLIDE 12

G

  • f
  • r

w a r d i n t

  • J

a v a 5 : G

  • f
  • r

w a r d i n t

  • J

a v a 5 : w h a t a r e n e e d e d ? w h a t a r e n e e d e d ?

  • S

u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s

– C

h a n g i n g t h e r e l a x a t i

  • n

r u l e f

  • r

s i g n a t u r e s

  • f

me t h

  • d

i n v

  • c

a t i

  • n

s

– C

h e c k i n g c

  • n

s i s t e n c y

  • f

v a l u e s d e r i v e d f r

  • m

t h e r e t u r n v a l u e f r

  • m

t h e j

  • i

n p

  • i

n t

  • S

u p p

  • r

t f

  • r

g e n e r i c s

– I

n f e r r i n g e r a s e d t y p e s

– C

h e c k i n g c

  • n

s i s t e n c y

  • f

v a l u e s d e r i v e d f r

  • m

t h e r e t u r n v a l u e f r

  • m

t h e j

  • i

n p

  • i

n t

D e r i v e d v a l u e s : L e t v a n d u a r e v a l u e s . v i s d e r i v e d f r

  • m

u i f v i s t h e r e t u r n v a l u e f r

  • m

x.m w h e r e x i s u

  • r

s

  • me

d e r i v e d v a l u e f r

  • m

u

slide-13
SLIDE 13

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s c

  • v

a r i a n t r e t u r n t y p e s g

  • e

s w r

  • n

g g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new BigIntStream();

  • = bs.get();

s = o.abs(); /* no bs, o and s*/ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k IntStream i s c

  • n

s i s t e n t w i t h Stream.get() BigInt BigIntStream.get() Object Stream.get() Not defined in Object

slide-14
SLIDE 14

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s c

  • v

a r i a n t r e t u r n t y p e s g

  • e

s w r

  • n

g g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new IntStream();

  • = bs.get();

s = o.abs(); /* no bs, o and s*/ IntStream around(): call(BigIntStream.new()){ return new IntStream(); }

V e r i f y E r r

  • r

Not defined in Object

slide-15
SLIDE 15

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

c

  • v

a r i a n t r e t u r n t y p e s c

  • v

a r i a n t r e t u r n t y p e s g

  • e

s w r

  • n

g g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new IntStream();

  • = bs.get();

s = o.abs(); /* no bs, o and s*/ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } Object Stream.get() BigInt BigInt.abs()

V e r i f y E r r

  • r

Not defined in Object O b j e c t i s u s e d a s B i g I n t = > E r r

  • r

!

slide-16
SLIDE 16

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

g e n e r i c s g

  • e

s w r

  • n

g g e n e r i c s g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } class Stream<X>{ X val; Stream(X v){val=v;} X get(){...} } bs=new Stream<BigInt>(...);

  • =bs.get();

s=o.abs(); /* no bs, o and s */ Stream<Int> around(): call(Stream<BigInt>.new(*)){ return new Stream<Int>(...); } C h e c k Stream<Int> i s c

  • n

s i s t e n t w i t h Stream<?Obj>.get() BigInt Stream<BigInt>.get() ?Obj Stream<?Obj>.get() ?Obj=? extends Object

slide-17
SLIDE 17

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

g e n e r i c s g

  • e

s w r

  • n

g g e n e r i c s g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } class Stream<X>{ X val; Stream(X v){val=v;} X get(){...} } bs=new Stream<Int>(...);

  • =bs.get();

s=o.abs(); /* no bs, o and s */ Stream<Int> around(): call(Stream<BigInt>.new(*)){ return new Stream<Int>(...); } ?Obj=? extends Object

Wr

  • n

g c

  • d

e

slide-18
SLIDE 18

S i m p l e s u p p

  • r

t f

  • r

S i m p l e s u p p

  • r

t f

  • r

g e n e r i c s g

  • e

s w r

  • n

g g e n e r i c s g

  • e

s w r

  • n

g

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } class Stream<X>{ X val; Stream(X v){val=v;} X get(){...} } bs=new Stream<Int>(...);

  • =bs.get();

s=o.abs(); /* no bs, o and s */ ?Obj Stream<?Obj>.get() ?Obj=? extends Object BigInt BigInt.abs() ? O b j i s u s e d a s B i g I n t = > E r r

  • r

Stream<Int> around(): call(Stream<BigInt>.new(*)){ return new Stream<Int>(...); }

Wr

  • n

g c

  • d

e

slide-19
SLIDE 19

O u r s

  • l

u t i

  • n

: c h e c k i n g c

  • n

s i s t e n c y O u r s

  • l

u t i

  • n

: c h e c k i n g c

  • n

s i s t e n c y

  • f
  • f

d e r i v e d d e r i v e d v a l u e s v a l u e s

  • Mo

d i f i e d t y p i n g p r i n c i p l e ( T R Wc ) : L e t adv b e a d v i c e a n d jp b e a j

  • i

n p

  • i

n t . adv c a n b e a p p l i e d t

  • jp

i f t h e r e t u r n t y p e

  • f

adv i s c

  • n

s i s t e n t w /

  • p

e r a t i

  • n

s

– u

s i n g retjp

– u

s i n g t h e d e r i v e d v a l u e s f r

  • m

retjp

t h e r e t u r n v a l u e f r

  • m

jp D e r i v e d v a l u e s : L e t v a n d u a r e v a l u e s . v i s d e r i v e d f r

  • m

u i f v i s t h e r e t u r n v a l u e f r

  • m

x.m w h e r e x i s u

  • r

s

  • me

d e r i v e d v a l u e f r

  • m

u

slide-20
SLIDE 20

E x a m p l e : c h e c k i n g E x a m p l e : c h e c k i n g c

  • n

s i s t e n c y

  • f

c

  • n

s i s t e n c y

  • f

d e r i v e d v a l u e s d e r i v e d v a l u e s

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new BigIntStream();

  • = bs.get();

s = o.abs(); /* no bs, o and s */ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k * IntStream<:Stream * Object<:BigInt BigInt BigIntStream.get() Object Stream.get() BigInt BigInt.abs() = > S u c c e s s f u l l y r e j e c t !

slide-21
SLIDE 21

E x a m p l e : c h e c k i n g E x a m p l e : c h e c k i n g c

  • n

s i s t e n c y

  • f

c

  • n

s i s t e n c y

  • f

d e r i v e d v a l u e s d e r i v e d v a l u e s

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new BigIntStream();

  • = bs.get();

s = o.toString(); /* no bs, o and s */ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k * IntStream <:Stream * Object<:Object BigInt BigIntStream.get() Object Stream.get() Objet BigInt.toString() = > S u c c e s s f u l l y a c c e p t ! Object Object.toString()

slide-22
SLIDE 22

F

  • r

m a l i z a t i

  • n

:

  • v

e r v i e w F

  • r

m a l i z a t i

  • n

:

  • v

e r v i e w

  • F

e a t h e r w e i g h t J a v a f

  • r

R e l a x a t i

  • n

w / c

  • v

a r i a n t r e t u r n t y p e s ( F J R c )

– S

i mp l e e x t e n s i

  • n

t

  • F

e a t h e r w e i g h t J a v a f

  • r

R e l a x a t i

  • n

( F J R )

[ Ma s u h a r a 1 ]

  • C

h e c k i n g c

  • n

s i s t e n c y : c

  • n

s t r a i n t s a t i s f a c t i

  • n

– G

e n e r a t e s u b t y p i n g c

  • n

s t r a i n t s f

  • r

e a c h F J R c e x p r e s s i

  • n

– I

f a s

  • l

u t i

  • n

i s f

  • u

n d , t h e w

  • v

e n c

  • d

e i s ( h

  • p

e f u l l y ) t y p e s a f e – p r

  • f

: f u t u r e w

  • r

k

slide-23
SLIDE 23

F e a t h e r w e i g h t J a v a f

  • r

R e l a x a t i

  • n

w / F e a t h e r w e i g h t J a v a f

  • r

R e l a x a t i

  • n

w / C

  • v

a r i a n t R e t u r n T y p e s ( F J R c ) C

  • v

a r i a n t R e t u r n T y p e s ( F J R c )

  • S

y n t a x : s a me t

  • F

J R

  • T

y p i n g r u l e s s u p p

  • r

t c

  • v

a r i a n t r e t u r n t y p e s

– P

r e d i c a t e

  • verride(m,C,T T0)

– C

l a s s t y p i n g r u l e

CL ::= class C extends C implements I { M } M ::= T m(T x){ return e; } IF ::= interface I { N } N ::= T m (T x); e ::= x | e.m(e) | new C() | let x = e in e | (?e:e) T ::= C | I U ::= T | U U ∪ n

  • n
  • d

e t e r mi n i s t i c c h

  • i

c e w

  • v

e n a d v i c e

slide-24
SLIDE 24

C

  • n

s t r a i n t g e n e r a t i

  • n

:

  • v

e r v i e w C

  • n

s t r a i n t g e n e r a t i

  • n

:

  • v

e r v i e w

  • C
  • n

s t r a i n t g e n e r a t i

  • n

a l g

  • r

i t h m c ::(G,e) (P,U) →

– T

y p i n g e n v i r

  • n

me n t G ::= x:T,G | .

– E

x p r e s s i

  • n

e

– S

u b t y p i n g c

  • n

s t r a i n t P={p} w h e r e p ::= S <: S | retT<:(m,S,S) S ::= C | I | X

– T

y p e U ::= S | U

∪ U

  • S
  • l

u t i

  • n

t

  • a

s u b t y p i n g c

  • n

s t r a i n t P: s u b s t i t u t i

  • n

[S/X] s . t . f

  • r

a l l p∈P. [S/X]p

t h e r e t u r n t y p e

  • f

S 1 . m i s a s u b t y p e

  • f

S 2

P1∪P2 P1∪P2

v a r i a b l e

slide-25
SLIDE 25

C

  • n

s t r a i n t g e n e r a t i

  • n

: C

  • n

s t r a i n t g e n e r a t i

  • n

: i n t e r e s t i n g c a s e i n t e r e s t i n g c a s e

  • Me

t h

  • d

i n v

  • c

a t i

  • n

e . m( e )

c(G,e0.m(e1,...,en))= let (P0,U0) = c(G,e0) in let (P,U) = c(G,e) in let T T = mtype(m,typeOf(e →

0)) in

let V = mdeftypes(m,typeOf(e ∪

0)) in

(P0∪ P { ∪ U<:T} {U ∪

0<:X1,X1<:V,retT<:(m,X1,X2)}

,X2) n

  • n
  • r

e l a x e d t y p e

  • f

e0 l e a s t u p p e r b

  • u

n d

  • f

t h e t y p e s t h a t d e f i n e m r e c e i v e r ' s t y p e c a n b e r e l a x e d c h e c k i n g d e r i v e d v a l u e s

slide-26
SLIDE 26

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • u

n s a f e c

  • d

e t y p e

  • u

n s a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let iabs = i.abs() in new Object(); }

slide-27
SLIDE 27

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • u

n s a f e c

  • d

e t y p e

  • u

n s a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let iabs = i.abs() in new Object(); } c(x:IntStream,BigIntStrm)= (x:IntStream,BigIntStrm) c(x:IntStream,IntStrm)= (x:IntStream,IntStrm) c(x:IntStream,(?BigIntStrm:x))= ({} {} ∪ , BigIntStrm IntStrm ∪ ) {}

slide-28
SLIDE 28

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • u

n s a f e c

  • d

e t y p e

  • u

n s a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let iabs = i.abs() in new Object(); } c((x:IntStrm,s:BigIntStrm IntStrm) ∪ ,s)= ({},BigIntStrm IntStrm ∪ ) mtype(get,typeOf(s))=() BigInt → ∪ mdeftypes(get,BigIntStrm)=Strm c((x:IntStrm,s:BigIntStrm IntStrm) ∪ ,s.get())= ({BigIntStrm IntStrm ∪ <:X1,X1<:Strm,retT<:(get,X1,X2} ,X2) {} {BigIntStrm IntStrm ∪ <:X1, X1<:Strm,retT<:(get,X1,X2)}

slide-29
SLIDE 29

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • u

n s a f e c

  • d

e t y p e

  • u

n s a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let iabs = i.abs() in new Object(); } c((x:IntStrm,s:BigIntStrm IntStrm,i: ∪ X2),i)= ({},X2) mtype(abs,typeOf(s))=() BigInt → ∪ mdeftypes(abs,BigInt)=BigInt c((x:IntStrm,s:BigIntStrm IntStrm,i: ∪ X2),i.abs())= ({X2<:X3,X3<:BigInt,retT<:(abs,X3,X4)} ,X4) {} {BigIntStrm IntStrm ∪ <:X1, X1<:Strm,retT<:(get,X1,X2)} {X2<:X3,X3<:BigInt, retT<:(abs,X3,X4)}

slide-30
SLIDE 30

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • u

n s a f e c

  • d

e t y p e

  • u

n s a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let iabs = i.abs() in new Object(); } {} {BigIntStrm IntStrm ∪ <:X1, X1<:Strm,retT<:(get,X1,X2)} {X2<:X3,X3<:BigInt, retT<:(abs,X3,X4)} BigIntStrm IntStrm ∪ <:X1<:Strm => X1=Strm retT<:(get,X1,X2) = retT<:(get,Strm,X2) => X2=Object X2<:X3<:BigInt = Object<:X3<:BigInt => False

slide-31
SLIDE 31

C

  • n

c l u s i

  • n

s a n d f u t u r e w

  • r

k C

  • n

c l u s i

  • n

s a n d f u t u r e w

  • r

k

  • T

y p e r e l a x e d w e a v i n g w / c

  • v

a r i a n t r e t u r n t y p e s ( a n d g e n e r i c s )

– C

h e c k i n g d e r i v e d v a l u e s i s n e c e s s a r y

  • C
  • n

s t r a i n t g e n e r a t i

  • n

a l g

  • r

i t h m f

  • r

F J R c

– C

h a n g e s f r

  • m

F J R : j u s t a b

  • u

t r e t u r n t y p e s

  • F

u t u r e w

  • r

k

– P

r

  • v

i n g t y p e s a f e t y

  • f

F J R c a n d s

  • u

n d n e s s

  • f

t h e a l g

  • r

i t h m

– I

mp l e me n t a t i

  • n
slide-32
SLIDE 32

E x a m p l e : c h e c k i n g E x a m p l e : c h e c k i n g c

  • n

s i s t e n c y

  • f

c

  • n

s i s t e n c y

  • f

d e r i v e d v a l u e s d e r i v e d v a l u e s

class Int{ Object toString(){...} } class BigInt{ Object toString(){...} BigInt abs(){...} } interface Stream{ Object get(); } class BigIntStream implements Stream{ BigInt get(){...} } class IntStream implements Stream{ Int get(){...} } bs = new BigIntStream();

  • = bs.get();

s = o.abs(); /* no bs, o and s */ IntStream around(): call(BigIntStream.new()){ return new IntStream(); } C h e c k * IntStream<: BigIntStream * BigInt<:BigInt BigInt BigIntStream.get() BigInt BigInt.abs() = > S u c c e s s f u l l y r e j e c t !

slide-33
SLIDE 33

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

E x a m p l e : c

  • n

t r a d i c t i

  • n

s f

  • u

n d

  • n

t y p e

  • s

a f e c

  • d

e t y p e

  • s

a f e c

  • d

e

Object m(){return let s = (?new BigIntStrm() :x) in let i = s.get() in let t = i.toStr() in new Object(); } {} {BigIntStrm IntStrm ∪ <:X1, X1<:Strm,retT<:(get,X1,X2)} {X2<:X3,X3<:Object, retT<:(toStr,X3,X4)} BigIntStrm IntStrm ∪ <:X1<:Strm => X1=Strm retT<:(get,X1,X2) = retT<:(get,Strm,X2) => X2=Object X2<:X3<:Object = Object<:X3<:Object => X3=Object retT<:(toStr,X3,X4) = retT<:(toStr,Object,X4) => X4=Str