+ All Categories
Home > Documents > The Genamics P rojec t

The Genamics P rojec t

Date post: 30-Jan-2016
Category:
Upload: abdalla
View: 38 times
Download: 1 times
Share this document with a friend
Description:
The Genamics P rojec t. – the interaction between generics and dynamics – Peter Achten, Ralf Hinze. Outline. Context & motivation The Genamics Project generic functions for labelled state transition systems dynamic instance creation of generic functions Conclusions. - PowerPoint PPT Presentation
28
The Genamics Project – the interaction between generics and dynamics – Peter Achten, Ralf Hinze
Transcript
Page 1: The Genamics  P rojec t

The Genamics Project

– the interaction between generics and dynamics –

Peter Achten, Ralf Hinze

Page 2: The Genamics  P rojec t

19-12-2001 The Genamics Project2

Outline

Context & motivation The Genamics Project

generic functions for labelled state transition systems

dynamic instance creation of generic functions

Conclusions

Page 3: The Genamics  P rojec t

19-12-2001 The Genamics Project3

Context & motivation

Functional I/O; GUIs; Clean Object I/O Programmer’s skill level:

higher-order functions, algebraic types (basic) algebraic type constructors (bit advanced) type constructor classes (advanced) Object I/O library (cope with ‘large’ library)

Page 4: The Genamics  P rojec t

19-12-2001 The Genamics Project4

Context & motivation (2)

Essential features of Object I/O: GUI objects are described by data structures Compositional to form more complex objects DSL: language elements (data types) + glue

rules (type constructor classes + instances) Labelled state transition system (initial state

values & higher order functions)

Page 5: The Genamics  P rojec t

19-12-2001 The Genamics Project5

Context & motivation (3)

Visual Editors (VE) provide mental metaphore for constructing GUIs

Constructed GUIs stored as resource persistent application independent usually contain no code separate development/enhancement

(modular)

Page 6: The Genamics  P rojec t

19-12-2001 The Genamics Project6

Context & motivation (4)

Support for GUIs requires VE Functional features to offer:

Static and dynamic typing Higher-order functions Abstraction (generic programming)

The Genamics project

Page 7: The Genamics  P rojec t

19-12-2001 The Genamics Project7

The Genamics project

Genamic = generic & dynamic Dynamic types: serialise GUI resources Generic functions: manipulate GUI

resources Results:

1. generic functions can manipulate labelled state systems.

2. generic functions strengthen dynamics

Page 8: The Genamics  P rojec t

19-12-2001 The Genamics Project8

Labelled state transition systems

Systems S1, S2, S3. Generic functions eval, param. Polykinded types approach by Hinze.

Page 9: The Genamics  P rojec t

19-12-2001 The Genamics Project9

System S1: actions

Behaviours are actions: *World *World Equivalent with Haskell Object I/O:

state in MVars monadic actions: IO ().

Page 10: The Genamics  P rojec t

19-12-2001 The Genamics Project10

S1 – DSL

data Obj obj = Obj Int (Id (W ())) obj

type Id x = x x

type W st = (st, *World)

instance S1 ()

instance (S1 s) S1 (Obj s)

instance (S1 s1,S1 s2) S1 (s1,s2)

Page 11: The Genamics  P rojec t

19-12-2001 The Genamics Project11

S1 – eval

Eval :: :: Eval t = t Int Id (W ())

Eval 1 2 t = x . Eval 1 x Eval 2 (t x)

eval t:: :: Eval teval 1 () _ = id

eval ea eb (a,b) nr = eb b nr ea a nr

eval + ea eb (Inl a) nr = ea a nr

eval + ea eb (Inr b) nr = eb b nr

eval Obj ea (Obj nr’ io a) nr = if nr’==nr then io else ea a nr

Page 12: The Genamics  P rojec t

19-12-2001 The Genamics Project12

S1 – example: actions

Example program:Start :: *World -> *World

Start w = case readDynamic “obj.dyn” w of

(True,obj :: (eval t) t, w) eval obj 1 w

_ w

Dynamic object in “obj.dyn”:dynamic ( Obj 0 (print “Hi there.”) ()

, Obj 2 (print “Goodbye”)

( Obj 1 (print “Hello world”) ())

) :: (Obj (), Obj (Obj ()))

Page 13: The Genamics  P rojec t

19-12-2001 The Genamics Project13

System S2: global state

System manages public state ps Behaviours: (ps,*World) (ps,*World) Objects:

data Obj obj ps = Obj Int (Id (W ps)) (obj ps)

Polykinded type scheme fails:Eval 1 2 t = x . Eval 1 x Eval 2 (t x)

Solution: lift kind level of equations = (1 2) = (1) (2)

Page 14: The Genamics  P rojec t

19-12-2001 The Genamics Project14

S2 – DSL

data Obj obj ps = Obj Int (Id (W ps)) (obj ps)

infixr 9 :~:

data :~: a b ps = (a ps) :~: (b ps)

data NilCS ps = NilCS

instance S2 NilCS

instance (S2 s) S2 (Obj s)

instance (S2 s1,S2 s2) S2 (:~: s1 s2)

Page 15: The Genamics  P rojec t

19-12-2001 The Genamics Project15

S2 – eval

Evalps :: ::

Evalps t = t ps Int Id (W ps)

Evalps (1 2 ) t = x . Evalps 1 x Evalps 2 (t x)

eval t :: :: ps . Evalps t

eval NilCS NilCS _ = id

eval :~: ea eb (a :~: b) nr= eb b nr ea a nr

eval + ea eb (InlCS a) nr= ea a nr

eval + ea eb (InrCS b) nr = eb b nr

eval Obj ea (Obj nr’ io a) nr = if nr’==nr then io else ea a nr

Page 16: The Genamics  P rojec t

19-12-2001 The Genamics Project16

S2 – example: global counter

Example program:Start :: *World -> *World

Start w = case readDynamic “obj.dyn” w of

(True,(st,obj) :: (eval t) (ps,t ps), w)

snd (eval obj 1 eval obj 0 eval obj 1 (st,w))

_ w

Dynamic object in “obj.dyn”:dynamic ( 1000, Obj 0 ((c,w) (c+1,w)) ()

:~: Obj 2 ((c,w) (c-1,w))

( Obj 1 ((c,w) (c, print (show c) w)) ())

) :: (Int, :~: (Obj ()) (Obj (Obj ()) Int)

Page 17: The Genamics  P rojec t

19-12-2001 The Genamics Project17

System S3: local & global state

System manages local and public state Equivalent with Clean Object I/O Objects:

data Obj obj ls ps = Obj Int (Id (W (ls,ps))) (obj ls ps)

Lift kind level of equations once more = (1 2) = (1) (2)

Hierarchy of stateful objects

Page 18: The Genamics  P rojec t

19-12-2001 The Genamics Project18

S3 – DSL

data Obj obj ls ps = Obj Int (Id (W (ls,ps))) (obj ls ps)data NewLS obj ls ps = new . NewLS new (obj new ps)data AddLS obj ls ps = add . AddLS add (obj (add,ls) ps)infixr 9 :+:data :+: a b ls ps = (a ls ps) :+: (b ls ps)data NilLS ls ps = NilLS

instance S3 NilLS

instance (S3 s) S3 (Obj s)

instance (S3 s1,S3 s2) S3 (:+: s1 s2 )

instance (S3 s) S3 (NewLS s)

instance (S3 s) S3 (AddLS s)

Page 19: The Genamics  P rojec t

19-12-2001 The Genamics Project19

S3 – eval

eval :: (S3 obj) Int Id (W (ps,obj () ps))

eval nr ((ps, obj), w)

= let (obj’, ((_,ps’), w’)) = eval’ obj nr (((),ps),w) in ((ps’,obj’),w’)

Eval’(ls,ps) :: ::

Eval’(ls,ps) t = t ls ps Int W (ls,ps) (t ls ps,W (ls,ps))

Eval’(ls,ps) (1 2 ) t = x . Eval’(ls,ps) 1 x Eval’(ls,ps) 2 (t x)

eval’ t :: :: ls . ps . Eval’(ls,ps) t

Page 20: The Genamics  P rojec t

19-12-2001 The Genamics Project20

S3 – eval (2)

Eval’(ls,ps) t = t ls ps Int W (ls,ps) (t ls ps,W (ls,ps))

eval’ t :: :: ls . ps . Eval’(ls,ps) t

eval’ NilLS NilLS _ wst = (NilLS,wst)

eval’ :+: ea eb (a :+: b) nr wst

= let (a',wst') = ea a nr wst

(b',wst'') = eb b nr wst

in (a' :+: b', wst'')

eval’ + ea eb (InlLS a) nr wst

= let (a',wst') = ea a nr wst in (InlLS a',wst')

eval’ + ea eb (InrLS b) nr wst

= let (b',wst') = eb b nr wst in (InrLS b',wst')

Page 21: The Genamics  P rojec t

19-12-2001 The Genamics Project21

S3 – eval (3)

Eval’(ls,ps) t = t ls ps Int W (ls,ps) (t ls ps,W (ls,ps))

eval’ t :: :: ls . ps . Eval’(ls,ps) teval’ Obj ea (Obj nr’ io a) nr ((ls,ps),w)

= if nr’==nr then let ((ls’,ps’),w’) = io ((ls,ps),w) in (((ls’,ps’),Obj nr’ io a), w’) else let (a’,((ls’,ps’),w’)) = ea a nr ((ls,ps),w)

in (((ls’,ps’),Obj nr’ io a’), w’) eval’ NewLS ea (NewLS new a) nr ((ls,ps),w)

= let (a’,((new’,ps’),w’)) = ea a nr ((new,ps),w) in (((ls,ps’),NewLS new’ a’), w’) eval’ AddLS ea (AddLS add a) nr ((ls,ps),w)

= let (a’,(((add’,ls’),ps’),w’)) = ea a nr (((add,ls),ps),w) in (((ls’,ps’),AddLS add’ a’), w’)

Page 22: The Genamics  P rojec t

19-12-2001 The Genamics Project22

S3 – example: local counter

Example program:Start :: *World -> *World

Start w = case readDynamic “obj.dyn” w of

(True,obj :: (eval’ t) t ls ps, w)

snd (eval 1 eval 0 eval 1 (((),obj),w)

_ w

Dynamic object in “obj.dyn”:dynamic ( NewLS 1000 (Obj 0 ((c,w) (c+1,w)) ()

:+: Obj 2 ((c,w) (c-1,w))

( Obj 1 ((c,w) (c, print (show c) w)) ())

) ::NewLS (:+: (Obj ()) (Obj (Obj ()))) ls ps

Page 23: The Genamics  P rojec t

19-12-2001 The Genamics Project23

Labelled state transition systems

Conclusions: Generic functions can be written for data

structures equivalent with Clean Object I/O Requires kind lifting in polykinded equations

Page 24: The Genamics  P rojec t

19-12-2001 The Genamics Project24

Dynamic generics

Generic function is defined for all types Instances resolved at compile-time For dynamic values resolve at run-time

Page 25: The Genamics  P rojec t

19-12-2001 The Genamics Project25

Dynamic generics (2)

Module M, options O, paths P, scope S:unwrap :: Dynamic t'

unwrap ( dyn :: (F a) t) = expr

Suppose offered type .1. Unify with t, yields substitution *.

2. Derive kind of a* = .

3. Generate f a* :: :: F a*.

4. Create module M' with name(M') = name(M)name(f)name(a*), content f a* :: :: F a*, and scope S.

5. Compile M' with options O and paths P M'.abc, M'.obj.

6. Dynamically link name(M')._name(f) for occurences of f in expr.

Page 26: The Genamics  P rojec t

19-12-2001 The Genamics Project26

Dynamic generics (3)

Module M, options O, paths P, scope S:wrap :: Dynamic

wrap = dynamic g :: G t

Suppose demanded type .1. Unify with G t, yields substitution * (or () ()).

2. Derive kind of * = .

3. Generate g * :: :: G *.

4. Create module M'' with name(M'') = name(M)name(g)name(*), content g * :: :: G *, and scope S.

5. Compile M'' with options O and paths P M''.abc, M''.obj.

6. Dynamically link name(M'')._name(g) for occurences of g in expr.

Page 27: The Genamics  P rojec t

19-12-2001 The Genamics Project27

Dynamic generics (4)

Advantages: reuse compiler components (kind inference,

generic instantiation, modular compilation, dynamic linking)

Disadvantages: many temporary files duplicate code, different scopes inefficient

Page 28: The Genamics  P rojec t

19-12-2001 The Genamics Project28

Conclusions (work to do)

Generic functions can be written for Object I/O-like data structures (should be tested)

For this we need kind lifting (should be generalised)

Run-time creation of generic instances for dynamic values seems feasible (build prototype)


Recommended