A Transformational Approach to Generic Software Development Based on Higher-Order, Typed Functional Signatures

Total Page:16

File Type:pdf, Size:1020Kb

A Transformational Approach to Generic Software Development Based on Higher-Order, Typed Functional Signatures A Transformational Approach to Generic Software Development Based on Higher-Order, Typed Functional Signatures Vom Promotionsausschuss der Technischen Universität Hamburg-Harburg zur Erlangung des akademischen Grades Doktor der Naturwissenschaften (Dr. rer. nat.) genehmigte Dissertation von Daniel Lincke aus Saalfeld 2012 Betreuer: Prof. Dr. Sibylle Schupp, Institut für Softwaresysteme, Technische Universität Hamburg- Harburg Zweitgutachter: Prof. Dr. Friedrich Mayer-Lindenberg, Institut für Rechnertechnologie, Technische Universität Hamburg-Harburg Drittgutachter: Prof. Dr. Carlo Jaeger, Global Climate Forum Berlin Datum der mündlichen Prüfung: 27. Juni 2012 URN: urn:nbn:de:gbv:830-tubdok-11682 Contents 1 Introduction1 1.1 Related Work...................................3 1.2 Motivating Example...............................4 1.3 Preliminaries and Notation............................6 1.3.1 Haskell..................................6 1.3.2 Concepts.................................7 1.3.3 C++ ....................................8 1.3.4 Backus-Naur Form (BNF)........................ 10 1.4 Contributions and Outline of the Thesis..................... 10 2 Functional, Higher-Order Types 12 2.1 An Overview of Type Systems.......................... 13 2.2 Untyped Lambda-Calculus............................ 15 2.3 Simply Typed Lambda-Calculus......................... 16 2.4 Polymorphic Lambda-Calculus (System F).................... 18 2.5 Lambda-Calculus with Type Constructors.................... 18 2.6 Kinds....................................... 20 2.7 Higher-Order Polymorphic Lambda-Calculus (System Fw )........... 21 2.8 Higher-Order Functional Types.......................... 23 2.9 Higher-Order Types and Object-Oriented Languages.............. 24 2.10 Types and Specification.............................. 25 2.11 Related Topics and Conclusion.......................... 26 3 Generic Software 28 3.1 Generic Programming............................... 28 3.2 Genericity..................................... 29 3.2.1 Genericity by value............................ 30 3.2.2 Genericity by type............................ 30 3.2.3 Genericity by function.......................... 30 3.2.4 Genericity by concepts (Genericity by structure)............ 31 3.2.5 Genericity by property.......................... 33 3.2.6 Genericity by stage............................ 33 3.2.7 Genericity by shape............................ 34 3.3 Polymorphism................................... 35 3.3.1 Universal polymorphism......................... 35 ii CONTENTS iii 3.3.2 Ad-hoc polymorphism.......................... 36 3.3.3 Concept-controlled polymorphism.................... 37 3.3.4 Genericity and polymorphism...................... 37 3.4 Related Topics and Conclusion.......................... 38 4 Program Transformation 39 4.1 Overview..................................... 40 4.2 Defunctionalisation................................ 42 4.3 Our Transformational Approach......................... 43 4.4 Related Topics and Conclusion.......................... 44 5 Kernel Languages 46 5.1 The Functional Type Kernel Language (FTKL).................. 46 5.1.1 Syntax.................................. 47 5.1.2 Kind rules................................. 49 5.1.3 Kind inference and kind checking.................... 50 5.1.4 Kind structure............................... 56 5.2 The Concept Type Kernel Language (CTKL)................... 57 5.2.1 Syntax.................................. 57 5.2.2 Kind rules................................. 58 5.2.3 Kind structure............................... 61 6 Transformation 63 6.1 Overview..................................... 63 6.2 Uncurrying of Type Constructor Applications.................. 66 6.3 Defunctionalisation of the Codomain of a Function Signature.......... 68 6.4 Defunctionalisation of the Domain of a Function Signature........... 71 6.5 Encoding Higher Kinded Type Variables..................... 74 6.6 Optimising Context................................ 75 6.7 The Complete Transformation and its Properties................. 77 7 Backends 79 7.1 Language Features................................ 81 7.1.1 ConceptC++ ................................ 81 7.1.2 Scala................................... 83 7.1.3 Haskell.................................. 85 7.1.4 Other languages............................. 86 7.2 ConceptC++ Backend............................... 89 7.3 Scala Backend................................... 91 7.4 Generic Haskell Backend............................. 94 7.5 Conclusion.................................... 96 8 Implementation 97 8.1 Architecture.................................... 97 8.2 Compiler..................................... 98 8.3 Performance.................................... 99 8.4 Test systems.................................... 104 CONTENTS iv 9 Applications 107 9.1 Higher-order Functions.............................. 108 9.2 Recursive Data Types as Fixed Points...................... 110 9.3 A Domain Specific Language for Vulnerability Modelling........... 111 9.3.1 Vulnerability formalisation and functional prototype.......... 112 9.3.2 Transformation and ConceptC++ implementation............ 115 10 Discussion, Outlook, and Conclusion 118 Bibliography 120 A Algorithms 129 A.1 Algorithm: find_fct................................ 129 A.2 Algorithm: replace_type............................. 130 B Test Output for ConceptC++ 131 C Transformation Output for Origami++ 137 C.1 Map........................................ 137 C.2 Fold........................................ 138 C.3 Unfold....................................... 139 C.4 Hylo........................................ 140 Acknowledgements 141 List of Figures 1.1 A very simple intermediate model of vulnerability, in Haskell and in FTKL ...5 1.2 The CTKL function signature of the vulnerability function...........5 1.3 The C++ function object generated from the CTKL function signature......6 2.1 The syntax of the untyped lambda-calculus................... 15 2.2 The syntax of the simply typed lambda-calculus................. 17 2.3 The typing rules of the simply typed lambda-calculus.............. 18 2.4 The syntax of the polymorphic lambda-calculus................. 19 2.5 The typing rules of the polymorphic lambda-calculus.............. 19 2.6 The relation between values, types, and kinds (after [Pierce, 2002])....... 21 2.7 The syntax of the lambda-calculus with type constructors............ 22 2.8 The kinding rules of the lambda-calculus with type constructors........ 22 2.9 The kinding rules of the lambda-calculus with type constructors........ 23 2.10 The lambda cube (from [Barendregt, 1991])................... 23 3.1 Kinds of polymorphism (from [Cardelli and Wegner, 1985]).......... 35 4.1 Transformation T and language bindings.................... 44 5.1 The syntax of FTKL ................................ 47 5.2 Derivation tree of the fold function signature from the Origami library in FTKL 48 5.3 Kind rules in FTKL ................................ 50 5.4 Kind checking for the signature of the fold function.............. 51 5.5 Computation of the local kinds for the fold function signature.......... 55 5.6 The fold signature in FTKL and its kind structure................ 57 5.7 The syntax of CTKL ................................ 58 5.8 Derivation of the fold function signature from the Origami library in CTKL .. 59 5.9 Kind rules in CTKL ................................ 60 5.10 The fold signature in CTKL and its kind structure................ 61 6.1 Specification of transformation T ........................ 77 7.1 A user-defined type constructor mapping..................... 80 7.2 Generic inversion in ConceptC++ ......................... 82 7.3 Generic inversion in Scala—with subtyping................... 84 7.4 Generic inversion in Scala—with implicits.................... 85 7.5 Generic inversion in Haskell........................... 86 v LIST OF FIGURES vi 7.6 Generic inversion in Java............................. 87 7.7 Generic inversion in D.............................. 88 7.8 Function concepts in C++ ............................. 89 7.9 TypeConstructor concepts in C++ ......................... 89 7.10 Function concepts in Scala............................ 92 7.11 Type constructor concepts in Scala........................ 92 7.12 Function concepts in Haskell........................... 95 7.13 Type constructor concepts in Haskell....................... 96 8.1 The architecture of our transformation system.................. 98 8.2 The compiler and its stages............................ 99 8.3 Function concept and function datatypes in C++ ................. 101 8.4 The test cases for the compiler.......................... 105 9.1 The Haskell function signatures we transform for the FCPPC library...... 108 9.2 The C++ implementation of function composition................ 109 9.3 Function signatures of the recursion operators of the Origami library...... 111 9.4 Function signatures of the list algebra implemented in Origami++ ........ 111 9.5 The function signatures of the vulnerability model prototype.......... 114 9.6 The vulnerability computation in ConceptC++ .................. 116 C.1 The generated function signatures of the map function.............. 137 C.2 The generated function signatures of the fold function.............. 138 C.3 The generated function signatures of the unfold function............ 139 C.4 The generated function signatures of the hylo function............. 140 List of Tables 1.1 BNF syntax used................................
Recommended publications
  • Administering Unidata on UNIX Platforms
    C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta UniData Administering UniData on UNIX Platforms UDT-720-ADMU-1 C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Notices Edition Publication date: July, 2008 Book number: UDT-720-ADMU-1 Product version: UniData 7.2 Copyright © Rocket Software, Inc. 1988-2010. All Rights Reserved. Trademarks The following trademarks appear in this publication: Trademark Trademark Owner Rocket Software™ Rocket Software, Inc. Dynamic Connect® Rocket Software, Inc. RedBack® Rocket Software, Inc. SystemBuilder™ Rocket Software, Inc. UniData® Rocket Software, Inc. UniVerse™ Rocket Software, Inc. U2™ Rocket Software, Inc. U2.NET™ Rocket Software, Inc. U2 Web Development Environment™ Rocket Software, Inc. wIntegrate® Rocket Software, Inc. Microsoft® .NET Microsoft Corporation Microsoft® Office Excel®, Outlook®, Word Microsoft Corporation Windows® Microsoft Corporation Windows® 7 Microsoft Corporation Windows Vista® Microsoft Corporation Java™ and all Java-based trademarks and logos Sun Microsystems, Inc. UNIX® X/Open Company Limited ii SB/XA Getting Started The above trademarks are property of the specified companies in the United States, other countries, or both. All other products or services mentioned in this document may be covered by the trademarks, service marks, or product names as designated by the companies who own or market them. License agreement This software and the associated documentation are proprietary and confidential to Rocket Software, Inc., are furnished under license, and may be used and copied only in accordance with the terms of such license and with the inclusion of the copyright notice.
    [Show full text]
  • A Polymorphic Type System for Extensible Records and Variants
    A Polymorphic Typ e System for Extensible Records and Variants Benedict R. Gaster and Mark P. Jones Technical rep ort NOTTCS-TR-96-3, November 1996 Department of Computer Science, University of Nottingham, University Park, Nottingham NG7 2RD, England. fbrg,[email protected] Abstract b oard, and another indicating a mouse click at a par- ticular p oint on the screen: Records and variants provide exible ways to construct Event = Char + Point : datatyp es, but the restrictions imp osed by practical typ e systems can prevent them from b eing used in ex- These de nitions are adequate, but they are not par- ible ways. These limitations are often the result of con- ticularly easy to work with in practice. For example, it cerns ab out eciency or typ e inference, or of the di- is easy to confuse datatyp e comp onents when they are culty in providing accurate typ es for key op erations. accessed by their p osition within a pro duct or sum, and This pap er describ es a new typ e system that reme- programs written in this way can b e hard to maintain. dies these problems: it supp orts extensible records and To avoid these problems, many programming lan- variants, with a full complement of p olymorphic op era- guages allow the comp onents of pro ducts, and the al- tions on each; and it o ers an e ective type inference al- ternatives of sums, to b e identi ed using names drawn gorithm and a simple compilation metho d.
    [Show full text]
  • Types and Programming Languages by Benjamin C
    < Free Open Study > . .Types and Programming Languages by Benjamin C. Pierce ISBN:0262162091 The MIT Press © 2002 (623 pages) This thorough type-systems reference examines theory, pragmatics, implementation, and more Table of Contents Types and Programming Languages Preface Chapter 1 - Introduction Chapter 2 - Mathematical Preliminaries Part I - Untyped Systems Chapter 3 - Untyped Arithmetic Expressions Chapter 4 - An ML Implementation of Arithmetic Expressions Chapter 5 - The Untyped Lambda-Calculus Chapter 6 - Nameless Representation of Terms Chapter 7 - An ML Implementation of the Lambda-Calculus Part II - Simple Types Chapter 8 - Typed Arithmetic Expressions Chapter 9 - Simply Typed Lambda-Calculus Chapter 10 - An ML Implementation of Simple Types Chapter 11 - Simple Extensions Chapter 12 - Normalization Chapter 13 - References Chapter 14 - Exceptions Part III - Subtyping Chapter 15 - Subtyping Chapter 16 - Metatheory of Subtyping Chapter 17 - An ML Implementation of Subtyping Chapter 18 - Case Study: Imperative Objects Chapter 19 - Case Study: Featherweight Java Part IV - Recursive Types Chapter 20 - Recursive Types Chapter 21 - Metatheory of Recursive Types Part V - Polymorphism Chapter 22 - Type Reconstruction Chapter 23 - Universal Types Chapter 24 - Existential Types Chapter 25 - An ML Implementation of System F Chapter 26 - Bounded Quantification Chapter 27 - Case Study: Imperative Objects, Redux Chapter 28 - Metatheory of Bounded Quantification Part VI - Higher-Order Systems Chapter 29 - Type Operators and Kinding Chapter 30 - Higher-Order Polymorphism Chapter 31 - Higher-Order Subtyping Chapter 32 - Case Study: Purely Functional Objects Part VII - Appendices Appendix A - Solutions to Selected Exercises Appendix B - Notational Conventions References Index List of Figures < Free Open Study > < Free Open Study > Back Cover A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute.
    [Show full text]
  • UNIX Workshop Series: Quick-Start Objectives
    Part I UNIX Workshop Series: Quick-Start Objectives Overview – Connecting with ssh Command Window Anatomy Command Structure Command Examples Getting Help Files and Directories Wildcards, Redirection and Pipe Create and edit files Overview Connecting with ssh Open a Terminal program Mac: Applications > Utilities > Terminal ssh –Y [email protected] Linux: In local shell ssh –Y [email protected] Windows: Start Xming and PuTTY Create a saved session for the remote host name centos.css.udel.edu using username Connecting with ssh First time you connect Unix Basics Multi-user Case-sensitive Bash shell, command-line Commands Command Window Anatomy Title bar Click in the title bar to bring the window to the front and make it active. Command Window Anatomy Login banner Appears as the first line of a login shell. Command Window Anatomy Prompts Appears at the beginning of a line and usually ends in $. Command Window Anatomy Command input Place to type commands, which may have options and/or arguments. Command Window Anatomy Command output Place for command response, which may be many lines long. Command Window Anatomy Input cursor Typed text will appear at the cursor location. Command Window Anatomy Scroll Bar Will appear as needed when there are more lines than fit in the window. Command Window Anatomy Resize Handle Use the mouse to change the window size from the default 80x24. Command Structure command [arguments] Commands are made up of the actual command and its arguments. command -options [arguments] The arguments are further broken down into the command options which are single letters prefixed by a “-” and other arguments that identify data for the command.
    [Show full text]
  • System Log Commands
    System Log Commands • system set-log , on page 2 • show system logging-level, on page 3 • show log, on page 4 System Log Commands 1 System Log Commands system set-log system set-log To set the log level and log type of messages, use the system set-log command in privileged EXEC mode. system set-log level {debug | info | warning | error | critical} logtype {configuration | operational | all} Syntax Description level Specifies the log level. debug Logs all messages. info Logs all messages that have info and higher severity level. warning Logs all messages that have warning and higher severity level. error Logs all messages that have error and higher severity level. critical Logs all messages that have critical severity level. logtype Specifies the log type. configuration Configuration log messages are recorded. operational Operational log messages are recorded. all All types of log messages are recorded. Command Default For the configuration log, info is the default level. For the operational log, warning is the default level. Command Modes Privileged EXEC (#) Command History Release Modification 3.5.1 This command was introduced. Usage Guidelines After a system reboot, the modified logging configuration is reset to the default level, that is, info for the configuration log and warning for the operational log. Example The following example shows how to configure a log level: nfvis# system set-log level error logtype all System Log Commands 2 System Log Commands show system logging-level show system logging-level To view the log level and log type settings, use the show system logging-level command in privileged EXEC mode.
    [Show full text]
  • From Perl to Python
    From Perl to Python Fernando Pineda 140.636 Oct. 11, 2017 version 0.1 3. Strong/Weak Dynamic typing The notion of strong and weak typing is a little murky, but I will provide some examples that provide insight most. Strong vs Weak typing To be strongly typed means that the type of data that a variable can hold is fixed and cannot be changed. To be weakly typed means that a variable can hold different types of data, e.g. at one point in the code it might hold an int at another point in the code it might hold a float . Static vs Dynamic typing To be statically typed means that the type of a variable is determined at compile time . Type checking is done by the compiler prior to execution of any code. To be dynamically typed means that the type of variable is determined at run-time. Type checking (if there is any) is done when the statement is executed. C is a strongly and statically language. float x; int y; # you can define your own types with the typedef statement typedef mytype int; mytype z; typedef struct Books { int book_id; char book_name[256] } Perl is a weakly and dynamically typed language. The type of a variable is set when it's value is first set Type checking is performed at run-time. Here is an example from stackoverflow.com that shows how the type of a variable is set to 'integer' at run-time (hence dynamically typed). $value is subsequently cast back and forth between string and a numeric types (hence weakly typed).
    [Show full text]
  • Declare New Function Javascript
    Declare New Function Javascript Piggy or embowed, Levon never stalemating any punctuality! Bipartite Amory wets no blackcurrants flagged anes after Hercules supinate methodically, quite aspirant. Estival Stanleigh bettings, his perspicaciousness exfoliating sopped enforcedly. How a javascript objects for mistakes to retain the closure syntax and maintainability of course, written by reading our customers and line? Everything looks very useful. These values or at first things without warranty that which to declare new function javascript? You declare a new class and news to a function expressions? Explore an implementation defined in new row with a function has a gas range. If it allows you probably work, regular expression evaluation but mostly warszawa, and to retain the explanation of. Reimagine your namespaces alone relate to declare new function javascript objects for arrow functions should be governed by programmers avoid purity. Js library in the different product topic and zip archives are. Why is selected, and declare a superclass method decorators need them into functions defined by allocating local time. It makes more sense to handle work in which support optional, only people want to preserve type to be very short term, but easier to! String type variable side effects and declarations take a more situations than or leading white list of merchantability or a way as explicit. You declare many types to prevent any ecmascript program is not have two categories by any of parameters the ecmascript is one argument we expect. It often derived from the new knowledge within the string, news and error if the function expression that their prototype.
    [Show full text]
  • Generic Programming
    Generic Programming July 21, 1998 A Dagstuhl Seminar on the topic of Generic Programming was held April 27– May 1, 1998, with forty seven participants from ten countries. During the meeting there were thirty seven lectures, a panel session, and several problem sessions. The outcomes of the meeting include • A collection of abstracts of the lectures, made publicly available via this booklet and a web site at http://www-ca.informatik.uni-tuebingen.de/dagstuhl/gpdag.html. • Plans for a proceedings volume of papers submitted after the seminar that present (possibly extended) discussions of the topics covered in the lectures, problem sessions, and the panel session. • A list of generic programming projects and open problems, which will be maintained publicly on the World Wide Web at http://www-ca.informatik.uni-tuebingen.de/people/musser/gp/pop/index.html http://www.cs.rpi.edu/˜musser/gp/pop/index.html. 1 Contents 1 Motivation 3 2 Standards Panel 4 3 Lectures 4 3.1 Foundations and Methodology Comparisons ........ 4 Fundamentals of Generic Programming.................. 4 Jim Dehnert and Alex Stepanov Automatic Program Specialization by Partial Evaluation........ 4 Robert Gl¨uck Evaluating Generic Programming in Practice............... 6 Mehdi Jazayeri Polytypic Programming........................... 6 Johan Jeuring Recasting Algorithms As Objects: AnAlternativetoIterators . 7 Murali Sitaraman Using Genericity to Improve OO Designs................. 8 Karsten Weihe Inheritance, Genericity, and Class Hierarchies.............. 8 Wolf Zimmermann 3.2 Programming Methodology ................... 9 Hierarchical Iterators and Algorithms................... 9 Matt Austern Generic Programming in C++: Matrix Case Study........... 9 Krzysztof Czarnecki Generative Programming: Beyond Generic Programming........ 10 Ulrich Eisenecker Generic Programming Using Adaptive and Aspect-Oriented Programming .
    [Show full text]
  • Java for Scientific Computing, Pros and Cons
    Journal of Universal Computer Science, vol. 4, no. 1 (1998), 11-15 submitted: 25/9/97, accepted: 1/11/97, appeared: 28/1/98 Springer Pub. Co. Java for Scienti c Computing, Pros and Cons Jurgen Wol v. Gudenb erg Institut fur Informatik, Universitat Wurzburg wol @informatik.uni-wuerzburg.de Abstract: In this article we brie y discuss the advantages and disadvantages of the language Java for scienti c computing. We concentrate on Java's typ e system, investi- gate its supp ort for hierarchical and generic programming and then discuss the features of its oating-p oint arithmetic. Having found the weak p oints of the language we pro- p ose workarounds using Java itself as long as p ossible. 1 Typ e System Java distinguishes b etween primitive and reference typ es. Whereas this distinc- tion seems to b e very natural and helpful { so the primitives which comprise all standard numerical data typ es have the usual value semantics and expression concept, and the reference semantics of the others allows to avoid p ointers at all{ it also causes some problems. For the reference typ es, i.e. arrays, classes and interfaces no op erators are available or may b e de ned and expressions can only b e built by metho d calls. Several variables may simultaneously denote the same ob ject. This is certainly strange in a numerical setting, but not to avoid, since classes have to b e used to intro duce higher data typ es. On the other hand, the simple hierarchy of classes with the ro ot Object clearly b elongs to the advantages of the language.
    [Show full text]
  • 13 Templates-Generics.Pdf
    CS 242 2012 Generic programming in OO Languages Reading Text: Sections 9.4.1 and 9.4.3 J Koskinen, Metaprogramming in C++, Sections 2 – 5 Gilad Bracha, Generics in the Java Programming Language Questions • If subtyping and inheritance are so great, why do we need type parameterization in object- oriented languages? • The great polymorphism debate – Subtype polymorphism • Apply f(Object x) to any y : C <: Object – Parametric polymorphism • Apply generic <T> f(T x) to any y : C Do these serve similar or different purposes? Outline • C++ Templates – Polymorphism vs Overloading – C++ Template specialization – Example: Standard Template Library (STL) – C++ Template metaprogramming • Java Generics – Subtyping versus generics – Static type checking for generics – Implementation of Java generics Polymorphism vs Overloading • Parametric polymorphism – Single algorithm may be given many types – Type variable may be replaced by any type – f :: tt => f :: IntInt, f :: BoolBool, ... • Overloading – A single symbol may refer to more than one algorithm – Each algorithm may have different type – Choice of algorithm determined by type context – Types of symbol may be arbitrarily different – + has types int*intint, real*realreal, ... Polymorphism: Haskell vs C++ • Haskell polymorphic function – Declarations (generally) require no type information – Type inference uses type variables – Type inference substitutes for variables as needed to instantiate polymorphic code • C++ function template – Programmer declares argument, result types of fctns – Programmers
    [Show full text]
  • Scala by Example (2009)
    Scala By Example DRAFT January 13, 2009 Martin Odersky PROGRAMMING METHODS LABORATORY EPFL SWITZERLAND Contents 1 Introduction1 2 A First Example3 3 Programming with Actors and Messages7 4 Expressions and Simple Functions 11 4.1 Expressions And Simple Functions...................... 11 4.2 Parameters.................................... 12 4.3 Conditional Expressions............................ 15 4.4 Example: Square Roots by Newton’s Method................ 15 4.5 Nested Functions................................ 16 4.6 Tail Recursion.................................. 18 5 First-Class Functions 21 5.1 Anonymous Functions............................. 22 5.2 Currying..................................... 23 5.3 Example: Finding Fixed Points of Functions................ 25 5.4 Summary..................................... 28 5.5 Language Elements Seen So Far....................... 28 6 Classes and Objects 31 7 Case Classes and Pattern Matching 43 7.1 Case Classes and Case Objects........................ 46 7.2 Pattern Matching................................ 47 8 Generic Types and Methods 51 8.1 Type Parameter Bounds............................ 53 8.2 Variance Annotations.............................. 56 iv CONTENTS 8.3 Lower Bounds.................................. 58 8.4 Least Types.................................... 58 8.5 Tuples....................................... 60 8.6 Functions.................................... 61 9 Lists 63 9.1 Using Lists.................................... 63 9.2 Definition of class List I: First Order Methods..............
    [Show full text]
  • Lambda Expressions
    Back to Basics Lambda Expressions Barbara Geller & Ansel Sermersheim CppCon September 2020 Introduction ● Prologue ● History ● Function Pointer ● Function Object ● Definition of a Lambda Expression ● Capture Clause ● Generalized Capture ● This ● Full Syntax as of C++20 ● What is the Big Deal ● Generic Lambda 2 Prologue ● Credentials ○ every library and application is open source ○ development using cutting edge C++ technology ○ source code hosted on github ○ prebuilt binaries are available on our download site ○ all documentation is generated by DoxyPress ○ youtube channel with over 50 videos ○ frequent speakers at multiple conferences ■ CppCon, CppNow, emBO++, MeetingC++, code::dive ○ numerous presentations for C++ user groups ■ United States, Germany, Netherlands, England 3 Prologue ● Maintainers and Co-Founders ○ CopperSpice ■ cross platform C++ libraries ○ DoxyPress ■ documentation generator for C++ and other languages ○ CsString ■ support for UTF-8 and UTF-16, extensible to other encodings ○ CsSignal ■ thread aware signal / slot library ○ CsLibGuarded ■ library for managing access to data shared between threads 4 Lambda Expressions ● History ○ lambda calculus is a branch of mathematics ■ introduced in the 1930’s to prove if “something” can be solved ■ used to construct a model where all functions are anonymous ■ some of the first items lambda calculus was used to address ● if a sequence of steps can be defined which solves a problem, then can a program be written which implements the steps ○ yes, always ● can any computer hardware
    [Show full text]