1 / 28

The Genamics P rojec t

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.

abdalla
Download Presentation

The Genamics P rojec t

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Outline • Context & motivation • The Genamics Project • generic functions for labelled state transition systems • dynamic instance creation of generic functions • Conclusions 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) 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) 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) 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 The Genamics Project

  7. The Genamics project • Genamic = generic & dynamic • Dynamic types: serialise GUI resources • Generic functions: manipulate GUI resources • Results: • generic functions can manipulate labelled state systems. • generic functions strengthen dynamics The Genamics Project

  8. Labelled state transition systems • Systems S1, S2, S3. • Generic functions eval, param. • Polykinded types approach by Hinze. The Genamics Project

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

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

  11. S1 – eval Eval k:: :: k Eval  t = t  Int  Id (W ()) Eval k1k2 t = x . Eval k1x  Eval k2 (t x) eval t::k :: Eval k 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 The Genamics Project

  12. 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 ())) The Genamics Project

  13. 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 k1k2 t = x . Eval k1x  Eval k2 (t x) • Solution: lift kind level of equations  =   (k1k2) =  (k1) (k2) The Genamics Project

  14. 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 S2NilCS instance (S2 s)  S2 (Obj s) instance (S2 s1,S2 s2)  S2 (:~: s1 s2) The Genamics Project

  15. S2 – eval Evalpsk:: :: k Evalps t = t ps Int  Id (W ps) Evalps(k1k2 ) t = x . Evalpsk1x  Evalpsk2 (t x) eval t :: k :: ps . Evalps k 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 The Genamics Project

  16. 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 (l(c,w) (c+1,w)) () :~: Obj 2 (l(c,w) (c-1,w)) ( Obj 1 (l(c,w) (c, print (show c) w)) ()) ) :: (Int, :~: (Obj ()) (Obj (Obj ()) Int) The Genamics Project

  17. 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  =   (k1k2) =  (k1) (k2) • Hierarchy of stateful objects The Genamics Project

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

  19. 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)k:: :: k Eval’(ls,ps) t = t ls ps  Int W (ls,ps)  (t ls ps,W (ls,ps)) Eval’(ls,ps)(k1k2 ) t = x . Eval’(ls,ps)k1x  Eval’(ls,ps)k2 (t x) eval’ t :: k :: ls . ps . Eval’(ls,ps) k t The Genamics Project

  20. S3 – eval (2) Eval’(ls,ps) t = t ls ps  Int W (ls,ps)  (t ls ps,W (ls,ps)) eval’ t :: k :: ls . ps . Eval’(ls,ps) k 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') The Genamics Project

  21. S3 – eval (3) Eval’(ls,ps) t = t ls ps  Int W (ls,ps)  (t ls ps,W (ls,ps)) eval’ t :: k :: ls . ps . Eval’(ls,ps) k t eval’ Obj ea (Obj nr’ io a) nr ((ls,ps),w) = if nr’==nr thenlet ((ls’,ps’),w’) = io ((ls,ps),w) in (((ls’,ps’),Obj nr’ io a), w’) elselet (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’) The Genamics Project

  22. 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 (l(c,w) (c+1,w)) () :+: Obj 2 (l(c,w) (c-1,w)) ( Obj 1 (l(c,w) (c, print (show c) w)) ()) ) ::NewLS (:+: (Obj ()) (Obj (Obj ()))) ls ps 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 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 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 t. • Unify t with t, yields substitution *. • Derive kind of a* = k. • Generate f  a* :: k :: F k a*. • Create module M' with name(M') = name(M)name(f)name(a*), content f  a* :: k :: F k a*, and scope S. • Compile M' with options O and paths P  M'.abc, M'.obj. • Dynamically link name(M')._name(f) for occurences of f in expr. The Genamics Project

  26. Dynamic generics (3) Module M, options O, paths P, scope S: wrap :: Dynamic wrap = dynamic g :: G k t Suppose demanded type t. • Unify t with G  t, yields substitution * (or ()()). • Derive kind of t* = k. • Generate g t* :: k :: G kt*. • Create module M'' with name(M'') = name(M)name(g)name(t*), content g t* :: k :: G kt*, and scope S. • Compile M'' with options O and paths P  M''.abc, M''.obj. • Dynamically link name(M'')._name(g) for occurences of g in expr. 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 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) The Genamics Project

More Related