Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Genamics Project – the interaction between generics and dynamics – Peter Achten, Ralf Hinze.

Similar presentations


Presentation on theme: "The Genamics Project – the interaction between generics and dynamics – Peter Achten, Ralf Hinze."— Presentation transcript:

1 The Genamics Project – the interaction between generics and dynamics – Peter Achten, Ralf Hinze

2 The Genamics Project 2 Outline Context & motivation The Genamics Project generic functions for labelled state transition systems dynamic instance creation of generic functions Conclusions

3 The Genamics Project 3 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)

4 The Genamics Project 4 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)

5 The Genamics Project 5 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)

6 The Genamics Project 6 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

7 The Genamics Project 7 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

8 The Genamics Project 8 Labelled state transition systems Systems S 1, S 2, S 3. Generic functions eval, param. Polykinded types approach by Hinze.

9 The Genamics Project 9 System S 1 : actions Behaviours are actions: *World  *World Equivalent with Haskell Object I/O: state in MVars monadic actions: IO ().

10 The Genamics Project 10 S 1 – DSL data Obj obj= Obj Int (Id (W ())) obj type Id x= x  x type W st= (st, *World) instance S 1 () instance (S 1 s)  S 1 (Obj s) instance (S 1 s 1,S 1 s 2 )  S 1 (s 1,s 2 )

11 The Genamics Project 11 S 1 – eval Eval   ::   ::    Eval    t= t  Int  Id (W ()) Eval   1   2  t=  x. Eval   1  x  Eval   2  (t x) eval  t::   :: Eval    t eval  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

12 The Genamics Project 12 S 1 – 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 ()))

13 The Genamics Project 13 System S 2 : 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 )

14 The Genamics Project 14 S 2 – 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 S 2 NilCS instance (S 2 s)  S 2 (Obj s) instance (S 2 s 1,S 2 s 2 )  S 2 (:~: s 1 s 2 )

15 The Genamics Project 15 S 2 – eval Eval ps   ::   ::    Eval ps     t= t ps  Int  Id (W ps) Eval ps   (  1   2 )  t=  x. Eval ps   1  x  Eval ps   2  (t x) eval   t ::    ::  ps. Eval ps      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

16 The Genamics Project 16 S 2 – 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)

17 The Genamics Project 17 System S 3 : 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

18 The Genamics Project 18 S 3 – 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 S 3 NilLS instance (S 3 s)  S 3 (Obj s) instance (S 3 s 1,S 3 s 2 )  S 3 (:+: s 1 s 2 ) instance (S 3 s)  S 3 (NewLS s) instance (S 3 s)  S 3 (AddLS s)

19 The Genamics Project 19 S 3 – eval eval :: (S 3 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

20 The Genamics Project 20 S 3 – 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')

21 The Genamics Project 21 S 3 – 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)      t eval’  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’)

22 The Genamics Project 22 S 3 – 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

23 The Genamics Project 23 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

24 The Genamics Project 24 Dynamic generics Generic function is defined for all types Instances resolved at compile-time For dynamic values resolve at run-time

25 The Genamics Project 25 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.

26 The Genamics Project 26 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.

27 The Genamics Project 27 Dynamic generics (4) Advantages: reuse compiler components (kind inference, generic instantiation, modular compilation, dynamic linking) Disadvantages: many temporary files duplicate code, different scopes inefficient

28 The Genamics Project 28 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)


Download ppt "The Genamics Project – the interaction between generics and dynamics – Peter Achten, Ralf Hinze."

Similar presentations


Ads by Google