200 likes | 429 Views
Clean 2.0. At last…. Rinus Plasmeijer University of Nijmegen www.cs.kun.nl/~clean. Clean version 2.0. New compiler rewritten in Clean (instead of C) Lots of small improvements in language - import mechanism (more precise, cyclic) - rank 2 polymorphism
E N D
Clean 2.0 At last….. Rinus Plasmeijer University of Nijmegen www.cs.kun.nl/~clean
Clean version 2.0 • New compiler rewritten in Clean (instead of C) • Lots of small improvements in language • - import mechanism (more precise, cyclic) • - rank 2 polymorphism • - multi-parameter type constructor classes • Support for Lazy / Strict / Unboxed lists • Experimental feature: dynamics • IDE: easy switching between different compilers / linkers • Sparkle ! • Not finished on time: support for Generic Programming
Clean version 2.0 • New compiler written in Clean (instead of C) • Lots of small improvements in language • - import mechanism (more precise, cyclic) • - rank 2 polymorphism • - multi-parameter type constructor classes • Support for Lazy / Strict / Unboxed lists • Experimental feature: dynamics • IDE: easy switching between different compilers / linkers • Sparkle ! • Not finished on time: support for Generic Programming
Lazy lists in Clean 1.3 Lazy lists are predefined data structures • Special syntax, list comprehensions, lots of predefined functions map:: (a b) [a] [b] map f [ ] = [ ] map f [x : xs] = [f x : map f xs] One can also define user-defined lists using an algebraic data type :: List a =Cons a (List a) | Nil mapl:: (a b) (List a) (List b) mapl f Nil = Nil mapl f (Cons x xs) = Cons (f x) (mapl f xs) • Different type as lazy list: cannot use nice syntax, nor any predefined function • But: one can make eager and unboxed list variants in this way
Lazy lists in Clean 1.3 Lazy lists are predefined data structures • Special syntax, list comprehensions, lots of predefined functions map:: (a b) [a] [b] map f [ ] = [ ] map f [x : xs] = [f x : map f xs] One can also define user-defined lists using an algebraic data type :: HList a =HCons!a (HList a) | HNil maph:: (a b) (HList a) (HList b) maphf HNil = HNil maphf (HConsx xs) = HCons(f x) (maphf xs) • Different type as lazy list: cannot use nice syntax, nor any predefined function • But: one can make eager and unboxed list variants in this way
Lazy lists in Clean 1.3 Lazy lists are predefined data structures • Special syntax, list comprehensions, lots of predefined functions map:: (a b) [a] [b] map f [ ] = [ ] map f [x : xs] = [f x : map f xs] One can also define user-defined lists using an algebraic data type :: EList a =ECons!a !(EList a) | ENil mape:: (a b) (EList a) (EList b) mapef ENil = ENil mapef (EConsx xs) = ECons(f x) (mapef xs) • Different type as lazy list: cannot use nice syntax, nor any predefined function • But: one can make eager and unboxed list variants in this way
Clean 2.0: syntax for lazy, strict, unboxed lists map:: (a b) [a] [b] // default lazy list map f [ ] = [ ] map f [x : xs] = [f x : map f xs] Syntax added for strict lists [! ], [ !], [!!] and unboxed lists[# ], [#!] maph:: (a b) [!a] [!b]// head strict list maphf [! ] = [! ] maphf [!x : xs] = [!f x :maphf xs] mapu:: (a b) [#Int!] [#Int!] // head unboxed+tail strict list of Int mapuf [# !] = [# !] mapuf [#x : xs!] = [#f x :mapuf xs!]
Overloading for lists using the class List map :: (a b) (m a) (n b) | List m a & List n b map f [|] = [|] map f [|x : xs] = [|f x :map f xs] • This overloaded definition can be used for all representations: [ ], [! ], [ !], [!!], [# ], [#!] • Overloading is used in the pattern match ! • Overloading mechanism takes care of specialization: • Automatically within the same module • Exported overloaded functions can be specialized on demand • No loss of efficiency
Clean version 2.0 • New compiler written in Clean (instead of C) • Lots of small improvements in language • - import mechanism (more precise, cyclic) • - rank 2 polymorphism • - multi-parameter type constructor classes • Support for Lazy / Strict / Unboxed lists • Experimental feature: dynamics • IDE: easy switching between different compilers / linkers • Sparkle ! • Not finished on time: support for Generic Programming
Why Dynamics ? • Exchange of data as well as code (!)in aneasyandtype-safeway • get rit of boring code for trivial I/O • Output : convert to some (string) format • Input: parser needed • typical 30% of program code • be able to store, retrieve and exchange code • add and combine plug-ins in a type-safe way • support the development of persistent programs • allow communication of arbitrary expressions between distributed applications • more expressive power
HybrideType System • Use keyworddynamic to change an expression of a statictype:: into the dynamic type :: Dynamic 3 :: Int dynamic 3 :: Dynamic map :: (a b) [a] [b]dynamic map :: Dynamic map square :: [Int] [Int]dynamic map square :: Dynamic • Use pattern matching to examine if an argument of dynamic type :: Dynamic is of a particular static type transform :: Dynamic [Int] transform (n :: Int) = [n] transform (f :: [Int] [Int]) = f [1..100] transform other = abort ”dynamic type error”
Dynamic Type Unification dynApply :: DynamicDynamic Dynamic dynApply (f :: a b) (x :: a) =dynamic (f x :: b) dynApply df dx = abort ”dynamic type error” dynApply2 :: DynamicDynamic b | TC b dynApply2 (f :: a b^) (x :: a) =f x :: b^ dynApply2 df dx = abort ”dynamic type error” • Run-time type checking, unification, type errors
Communicating Dynamics • write + read Dynamics with one instruction writeDynamic :: Dynamic*File *File readDynamic :: *File (Dynamic, *File) sendDynamic :: Dynamic*Channel *Channel
CleanSystem 2.0 • .icl • .dcl • .pcl • I ntegrated • D evelopment • E nvironment • Project Manager • Editor • Clean • TimeProfiler • Clean • Compiler Clean /C • .abc • .chp • HeapProfiler • Clean • Code Generator C RTS C • .obj • .obj • Sparkle • Clean • Static Linker Clean • Application • Clean
CleanDynamic Linker • Static Linker Clean • Applic. 1 Image • obj • Dynamic Linker • Clean • Applic. 2 Image • obj • App 1 • Plug-in • Clean • Plug-in • Clean • Plug-in • Clean • App 2 • dynamic • .icl • .dcl • I ntegrated • D evelopment • E nvironment • Project Manager • Editor • Clean • Compiler Clean /C • .abc • Code Generator C RTS C • .obj • .obj
Dynamics: Easy to use, hard to implement ! • Writing of a Dynamic: • Expression is stored, sharing maintained, nested dynamics allowed • Type of the Dynamic is stored • Store references to applications images containing the code type definitions • Reading of a Dynamic is done lazily: • Nothing happens until its type is required in a pattern match • Linking of code only happens if all types in the rule match and can be unifiedand all type definitions involved in the Dynamics and the application are identical • If the rule matches, the expression is constructed as far as needed • Constructors of the same type must have the same address ! • The code needed for evaluation not yet linked in will be linked in (Plug-in)
Demo applications using Dynamics • Visual Editor (work in progress) • Resource editor for defining dialogs, windows, menu’s • Stores it’s definitions in a Dynamic • Definitions are a plug-in for the application • Application can change it’s look by using the Visual Editor as plug-in • FAMKE -Functional Micro Kernel Experiment (work in progress) • Very Tiny Operating System: only type safe operations ! • Special File Manager: Files contain Dynamics • Executables (:: a -> b), Data (:: T a b c) • Process creation and communication using Dynamics • Type safe Unix-like shell (pipes) using process combinators • Data Base support
Clean Compiler version 2.0 • Status • Front end compiler completely rewritten in Clean • We have added some interesting new features • All Clean 1.3 applications (IDE, Sparkle, compiler) ported and tested • Speed: about 1.7 slower than C version • See: www.cs.kun.nl/~clean (13.2 Mb zipped, open source) • Work to do • Test compiler for new features, wrong programs • Dynamics + uniqueness typing, universal quantified types … • Add support for generic programming • Improve fusion algorithm to reduce generics overhead • Port to Mac OS X (carbon/PEF), Linux
STW crew Diederik van Arkel (16-9-2003) Integrated Development Environment Fusion Algorithm Martijn Vervoort (16-9-2003) Dynamics + Dynamic Linker Arjen van Weelden (1-10-2002) Demo Application: Famke KUN crew John van Groningen Compiler, Code generator Ronny Wichers - Schreur Compiler Testing KUN PhD researchers Maarten de Mol Sparkle: Proof System Artem Alimarine Generic Programming KUN MSc students Arvid Nicolaas Demo Application: Visual Editor KUN staf Peter Achten Generics / IO / Visual Editor Pieter Koopman compiler (parser/checking) Sjaak Smetsers compiler (typing, testing) Marko van Eekelen Semantics Clean + Sparkle Rinus Plasmeijer Project leader The Clean Team