Nullable Type Inference

Total Page:16

File Type:pdf, Size:1020Kb

Nullable Type Inference Nullable Type Inference Michel Mauny Benoît Vaugon Unité d’Informatique et d’Ingénierie des Systèmes (U2IS) ENSTA-ParisTech France {michel.mauny,benoit.vaugon} <at> ensta-paristech.fr We present type inference algorithms for nullable types Now, the compilation of Some(expr) needs to generate a in ML-like programming languages. Starting with a sim- test, in order to use the special representation of Somen(None) ple system, presented as an algorithm, whose only inter- when expr evaluates to None, and pattern-matching against est is to introduce the formalism that we use, we replace Some=None also needs to be adjusted. unification by subtyping constraints and obtain a more in- teresting system. We state the usual properties for both systems. This is work in progress. This paper does not aim at opposing nullable types to op- tion types. Options, in the Hindley-Milner type discipline, offer not only type safety, but also precision by distinguish- 1 Nullable vs. option types ing Some(None) from None, but at the price of a memory al- location or a dynamic test for Some. On the other hand, nul- Imperative programming languages, such as C or Java deriva- lable types extend any classical type t into t?, to include NULL. tives, make abundant use of NULL either as a value for un- Such “nullable values” are easier to represent and compile known or invalid references, or as failure return values. Us- than options, but offer less precision since it makes no sense NULL if ing is rather practical, since the statement suffices for to extend further t?. Also, their static inference haven’t re- checking NULL-ity. Of course, the downside of having NULL as ceived much attention, so far. Indeed, although quite a few a possible value is that, without further support, it could acci- recent programming laguages statically check the safety of dentally be confused with a legal value, leading to execution NULL [3, 2, 11, 1], none of them really performs type infer- errors [7]. ence in the ML sense, but rather local inference, propagat- In languages using the ML type discipline, the option type ing mandatory type annotations of function parameters in- type α option = None | Some of α side the function bodies. injects regular values and the nullary data constructor None, into a single type that could be thought as a nullable type. 2 Nullable type inference The type system guarantees that options cannot be confused with regular values, and pattern-matching is used to check and extract regular values from options. In Haskell, the The purpose of this work is to study type inference of nul- “maybe” data type is heavily used for representing successes lable types, by adding them as a feature in a small functional and failures. The JaneStreet Core library [9] uses the option language. The language that we consider, given in figure 1, type to show possible failures in function types: it purposely is a classical mini-ML, extended with NULL test and creation. avoids exceptions, because their non-appearance in OCaml Section 3 starts with a naïve approach, where the types τ types hides the partiality of functions. In OCaml, None and Some are automatically inserted by the compiler for dealing c ::= () true f alse 0 1 2 ::: + ::: with optional arguments [5]. j j j j j j j j e ::= c x λx:e e e if e then e else e Using the option data type presents the disadvantage of j j j 1 2 j 1 2 3 let x = e in e allocating memory blocks for representing Some(_) values, j 1 2 NULL case e1 of NULL e2 x e3 which may refrain experienced programmers from heavily us- j j k ing options. Avoiding those memory allocations is not really difficult: if Some(v) is represented as v itself, that is, without Figure 1: The language allocating a block tagged as Some, we need a special represen- tation for None, distinct from the representation of v, for any v. Of course, when v is None itself, it then becomes impossi- (that are assigned to expressions e) are pairs (t; ν) of a usual ble to distinguish Some(None) from None. Therefore, None is type t and a “nullability” type information ν. A type (t; ?) cor- not the only special case that needs a special treatment: the responds to values that may be NULL, whereas (t; ∆) denotes whole range of Somen(None) values, for n 0 needs a spe- values that cannot be NULL. Nullability variables are written cial representation such that Somei(None) cannot≥ be confused δ. This system is mainly used to introduce the formalism that with Somej(None) when i , j. we use for writing our algorithms. For instance, unaligned addresses on 64-bits architectures, Section 4 shows a translation algorithm that encode nul- or a statically pre-allocated array of a sufficient size could do lable values with polymorphic variants. Typing the trans- the job1. lated programs with a unification-based mechanism suffers the same weakness as our naive type system. 1Although polymorphic recursion theoretically allows for unbounded depth of Somen(None) while this representation allows for representing only Section 5 presents a more sophisticated typing mechanism, a finite number of n, this limitation should never be met in practice. where unification is replaced by subtyping constraints. Submitted to ML 2014 2 TCONST TINSTVAR TINST(α) Φ τ = T(c) B Φ0 Φ τ0 = τ B Φ0 let α0 fresh Φ; Γ x : σ[α α0] x : τ B Φ0 ` ` ⊕ ` Φ; Γ c : τ B Φ0 Φ; Γ x : τ0 x : τ B Φ0 Φ; Γ x : α.σ x : τ B Φ0 ` ⊕ ` ⊕ 8 ` TINST(δ) let δ0 fresh Φ; Γ x : σ[δ δ0] x : τ B Φ0 ⊕ ` Φ; Γ x : δ.σ x : τ B Φ0 ⊕ 8 ` TLAMBDA let α ; δ ; α ; δ fresh Φ; Γ x :(α ; δ ) e :(α ; δ ) B Φ0 Φ0 τ = (α ; δ ) (α ; δ ) B Φ00 1 1 2 2 ⊕ 1 1 ` 2 2 ` 1 1 ! 2 2 Φ; Γ λx:e : τ B Φ00 ` TAPP let α, δ fresh Φ; Γ e : ((α, δ) τ); ∆) B Φ0 Φ0; Γ e :(α, δ) B Φ00 ` 1 ! ` 2 Φ; Γ e e : τ B Φ00 ` 1 2 TLET let α, δ fresh Φ; Γ e :(α, δ) B Φ0 Φ0; Γ x : gen(Φ0; Γ; (α, δ)) e : τ B Φ00 ` 1 ⊕ ` 2 Φ; Γ let x = e in e : τ B Φ00 ` 1 2 TIFTHENELSE TNULL Φ; Γ e :(bool; ∆) B Φ0 Φ0; Γ e : τ B Φ00 Φ00; Γ e : τ B Φ000 let α fresh Φ τ = (α, ?) B Φ0 ` 1 ` 2 ` 3 ` Φ; Γ if e then e else e : τ B Φ000 Φ; Γ NULL : τ B Φ0 ` 1 2 3 ` TCASE let δ fresh Φ; Γ e :(t; ?) B Φ0 Φ0; Γ e : τ B Φ00 Φ00; Γ x : δ:(t; δ) e : τ B Φ000 ` 1 ` 2 ⊕ 8 ` 3 Φ; Γ case e1 of NULL e2 x e3 : τ B Φ000 ` k Figure 3: Typing rules gen(Φ; Γ; τ) = gen0(Φ(Γ); Φ(τ)) τ ::= (t; ν) t ::= tb α τ1 τ2 µα.τ j j ! j gen0(Γ; σ) = gen0(Γ; α.σ) when α FTV(σ) α < FTV(Γ) tb ::= unit bool int ν ::= ? δ ∆ 8 2 ^ j j j j gen0(Γ; σ) = gen0(Γ; δ.σ) when δ FTV(σ) δ < FTV(Γ) 8 2 ^ gen0(Γ; σ) = σ otherwise Figure 2: The types Figure 4: Generalisation 3 A simple type system or merge (EQMERGE) variable bindings in the Φ substitution. EQNEW , installs a binding in the substitution We first present a rather simple type system, where the types (α) α = t0 Φ[α (that is, in which free occurences of are replaced by carry a “nullability information” saying whether the value of t0] Φ α ) when there is no previous binding about in . Here, an expression may be NULL or not. t0 α Φ t0 is either t or t, depending on whether occurs or not in t. The judgements of our language’s type system are of the µα. α EQNEW(δ) does the same, in a simpler context, on nullability form Φ; Γ e :(t; ν) B Φ , where Φ and Φ are substitutions, Γ 0 0 variables. is a type environment` that maps program identifiers to type EQMERGE merges a new constraint t to a previous schemes (types with a prenex universal quantification of type (α) α = 0 t occuring in . Here, the resulting substitution is and nullability variables). Such a judgement should be read α = Φ Φ0 obtained by resolving the constraint t = t . EQMERGE(δ) does as: given Φ, under assumption Γ, the expression e has type τ 0 the same for nullability variables. with substitution Φ . 0 Correctness. The operational semantics needed for stating The rules should be read as the different cases of an al- the correction of the type system is also classical. NULL cannot gorithm that, given Φ, Γ, e, and τ, computes substitution Φ 0 handle operations such as being called as a function, tested which, when applied to τ and Γ, assign the type Φ (τ) to e. In 0 as a boolean, added as an integer, etc. The typing of values, other words, under assumptions Φ (Γ), e has type Φ (τ). 0 0 procuded by correct executions, is also slightly changed: the Because we have two kinds of variables, we have two in- type (t; ?) includes NULL as well as regular values.
Recommended publications
  • Atd Documentation Martin Jambon
    atd Documentation Martin Jambon May 03, 2020 Contents 1 Tutorial 1 1.1 What is atdgen?.............................................1 1.2 What are the advantages of atdgen?...................................1 1.3 Prerequisites...............................................1 1.4 Getting started..............................................2 1.5 Inspecting and pretty-printing JSON...................................3 1.6 Inspecting biniou data..........................................4 1.7 Optional fields and default values....................................6 1.8 Smooth protocol upgrades........................................7 1.8.1 Adding or removing an optional record field..........................7 1.8.2 Adding a required record field.................................8 1.8.3 Removing a required record field................................8 1.8.4 Adding a variant case......................................8 1.8.5 Removing a variant case....................................8 1.8.6 Avoiding future problems....................................8 1.9 Data validation..............................................9 1.10 Modularity: referring to type definitions from another ATD file.................... 12 1.11 Managing JSON configuration files................................... 13 1.12 Integration with ocamldoc........................................ 17 1.13 Integration with build systems...................................... 18 1.13.1 OMake............................................. 18 1.13.2 GNU Make........................................... 19 1.13.3
    [Show full text]
  • Chapter 5 Type Declarations
    Ch.5: Type Declarations Plan Chapter 5 Type Declarations (Version of 27 September 2004) 1. Renaming existing types . 5.2 2. Enumeration types . 5.3 3. Constructed types . 5.5 4. Parameterised/polymorphic types . 5.10 5. Exceptions, revisited . 5.12 6. Application: expression evaluation . 5.13 °c P. Flener/IT Dept/Uppsala Univ. FP 5.1 Ch.5: Type Declarations 5.1. Renaming existing types 5.1. Renaming existing types Example: polynomials, revisited Representation of a polynomial by a list of integers: type poly = int list ² Introduction of an abbreviation for the type int list ² The two names denote the same type ² The object [4,2,8] is of type poly and of type int list - type poly = int list ; type poly = int list - type poly2 = int list ; type poly2 = int list - val p:poly = [1,2] ; val p = [1,2] : poly - val p2:poly2 = [1,2] ; val p2 = [1,2] : poly2 - p = p2 ; val it = true : bool °c P. Flener/IT Dept/Uppsala Univ. FP 5.2 Ch.5: Type Declarations 5.2. Enumeration types 5.2. Enumeration types Declaration of a new type having a finite number of values Example (weekend.sml) datatype months = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec datatype days = Mon | Tue | Wed | Thu | Fri | Sat | Sun fun weekend Sat = true | weekend Sun = true | weekend d = false - datatype months = Jan | ... | Dec ; datatype months = Jan | ... | Dec - datatype days = Mon | ... | Sun ; datatype days = Mon | ... | Sun - fun weekend ... ; val weekend = fn : days -> bool °c P. Flener/IT Dept/Uppsala Univ. FP 5.3 Ch.5: Type Declarations 5.2.
    [Show full text]
  • Nominal Wyvern: Employing Semantic Separation for Usability Yu Xiang Zhu CMU-CS-19-105 April 2019
    Nominal Wyvern: Employing Semantic Separation for Usability Yu Xiang Zhu CMU-CS-19-105 April 2019 School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 Thesis Committee: Jonathan Aldrich, Chair Heather Miller Alex Potanin, Victoria University of Wellington, NZ Submitted in partial fulfillment of the requirements for the degree of Master of Science. Copyright c 2019 Yu Xiang Zhu Keywords: Nominality, Wyvern, Dependent Object Types, Subtype Decidability Abstract This thesis presents Nominal Wyvern, a nominal type system that empha- sizes semantic separation for better usability. Nominal Wyvern is based on the dependent object types (DOT) calculus, which provides greater expressiv- ity than traditional object-oriented languages by incorporating concepts from functional languages. Although DOT is generally perceived to be nominal due to its path-dependent types, it is still a mostly structural system and relies on the free construction of types. This can present usability issues in a subtyping- based system where the semantics of a type are as important as its syntactic structure. Nominal Wyvern overcomes this problem by semantically separat- ing structural type/subtype definitions from ad hoc type refinements and type bound declarations. In doing so, Nominal Wyvern is also able to overcome the subtype undecidability problem of DOT by adopting a semantics-based sep- aration between types responsible for recursive subtype definitions and types that represent concrete data. The result is a more intuitive type system that achieves nominality and decidability while maintaining the expressiveness of F-bounded polymorphism that is used in practice. iv Acknowledgments This research would not have been possible without the support from the following in- dividuals.
    [Show full text]
  • Cablelabs® Specifications Cablelabs' DHCP Options Registry CL-SP-CANN-DHCP-Reg-I13-160317
    CableLabs® Specifications CableLabs' DHCP Options Registry CL-SP-CANN-DHCP-Reg-I13-160317 ISSUED Notice This CableLabs specification is the result of a cooperative effort undertaken at the direction of Cable Television Laboratories, Inc. for the benefit of the cable industry and its customers. You may download, copy, distribute, and reference the documents herein only for the purpose of developing products or services in accordance with such documents, and educational use. Except as granted by CableLabs in a separate written license agreement, no license is granted to modify the documents herein (except via the Engineering Change process), or to use, copy, modify or distribute the documents for any other purpose. This document may contain references to other documents not owned or controlled by CableLabs. Use and understanding of this document may require access to such other documents. Designing, manufacturing, distributing, using, selling, or servicing products, or providing services, based on this document may require intellectual property licenses from third parties for technology referenced in this document. To the extent this document contains or refers to documents of third parties, you agree to abide by the terms of any licenses associated with such third-party documents, including open source licenses, if any. Cable Television Laboratories, Inc. 2006-2016 CL-SP-CANN-DHCP-Reg-I13-160317 CableLabs® Specifications DISCLAIMER This document is furnished on an "AS IS" basis and neither CableLabs nor its members provides any representation or warranty, express or implied, regarding the accuracy, completeness, noninfringement, or fitness for a particular purpose of this document, or any document referenced herein. Any use or reliance on the information or opinion in this document is at the risk of the user, and CableLabs and its members shall not be liable for any damage or injury incurred by any person arising out of the completeness, accuracy, or utility of any information or opinion contained in the document.
    [Show full text]
  • CA Application Performance Management API Reference Guide
    CA Application Performance Management API Reference Guide Release 9.5 This Documentation, which includes embedded help systems and electronically distributed materials, (hereinafter referred to as the “Documentation”) is for your informational purposes only and is subject to change or withdrawal by CA at any time. This Documentation may not be copied, transferred, reproduced, disclosed, modified or duplicated, in whole or in part, without the prior written consent of CA. This Documentation is confidential and proprietary information of CA and may not be disclosed by you or used for any purpose other than as may be permitted in (i) a separate agreement between you and CA governing your use of the CA software to which the Documentation relates; or (ii) a separate confidentiality agreement between you and CA. Notwithstanding the foregoing, if you are a licensed user of the software product(s) addressed in the Documentation, you may print or otherwise make available a reasonable number of copies of the Documentation for internal use by you and your employees in connection with that software, provided that all CA copyright notices and legends are affixed to each reproduced copy. The right to print or otherwise make available copies of the Documentation is limited to the period during which the applicable license for such software remains in full force and effect. Should the license terminate for any reason, it is your responsibility to certify in writing to CA that all copies and partial copies of the Documentation have been returned to CA or destroyed. TO THE EXTENT PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS DOCUMENTATION “AS IS” WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NONINFRINGEMENT.
    [Show full text]
  • Declare Property Class Accept Null C
    Declare Property Class Accept Null C Woesome and nontechnical Joshuah planned inveterately and pull-outs his frontiers sourly and daftly. Unquiet Bernard fly-by very instructively while Rick remains ectotrophic and chastened. Sometimes stereoscopic Addie unnaturalizes her acorns proportionally, but unlidded Cat invert heinously or orientalizes rancorously. Even experts are accepted types and positional parameters and references, and assigns to. Use HasValue property to check has value is assigned to nullable type sometimes not Static Nullable class is a. Thank you declare more freely, declare property class accept null c is useful to provide only one dispiriting aspect of. Here we're defining a suggest that extracts all non-nullable property keys from plant type. By disabling cookies to accept all? The car variable inside counter Person class shouldn't be declared type grass and. Use JSDoc type. Any class property name, null safe code token stream of properties and corresponds to accept a class! Why death concept of properties came into C The decline because not two reasons If the members of a class are private then select another class in C. JavaScript Properties of variables with null or undefined. Type cup type as should pickle the null value variable the pastry of the variable to which null. CS31 Intro to C Structs and Pointers. Using the New Null Conditional Operator in C 6 InformIT. Your extra bet is to get themselves the good group of initializing all variables when you disabled them. This class that null values can declare variables declared inside an exception handling is nullable context switches a varargs in.
    [Show full text]
  • Project Overview 1 Introduction 2 a Quick Introduction to SOOL
    CMSC 22600 Compilers for Computer Languages Handout 1 Autumn 2016 October 6, 2016 Project Overview 1 Introduction The project for the course is to implement a small object-oriented programming language, called SOOL. The project will consist of four parts: 1. the parser and scanner, which coverts a textual representation of the program into a parse tree representation. 2. the type checker, which checks the parse tree for type correctness and produces a typed ab- stract syntax tree (AST) 3. the normalizer, which converts the typed AST representation into a static single-assignment (SSA) representation. 4. the code generator, which takes the SSA representation and generates LLVM assembly code. Each part of the project builds upon the previous parts, but we will provide reference solutions for previous parts. You will implement the project in the Standard ML programming language and submission of the project milestones will be managed using Phoenixforge. Important note: You are expected to submit code that compiles and that is well documented. Points for project code are assigned 30% for coding style (documentation, choice of variable names, and program structure), and 70% for correctness. Code that does not compile will not receive any points for correctness. 2 A quick introduction to SOOL SOOL is a statically-typed object-oriented language. It supports single inheritance with nominal subtyping and interfaces with structural subtyping. The SOOL version of the classic Hello World program is class main () { meth run () -> void { system.print ("hello world\n"); } } Here we are using the predefined system object to print the message. Every SOOL program has a main class that must have a run function.
    [Show full text]
  • C# Datetime Null Values
    C# datetime null values click here to download That will now set the result to null if dateTimeEnd isn't valid. Note that TryParse DateTime is a non-nullable value type c# Nullable Datetime. This C# example program uses a nullable DateTime instance. GetValueOrDefault()); } static void Test(DateTime? value) { // // This method uses the HasValue. Hi, How can I assign Null value to datetime? you need to assign like this in C#. DateTime? variablename = null;. Regards, GopalChettri (MCP). Free source code and tutorials for Software developers and Architects.; Updated: 10 Jun I'm writing a C# program to www.doorway.ru files from SQL 2)How to I set a DateTime field to null? Thanks, Marcie. Friday DateTime may be declared as nullable, that's to say no value may be affected to it. Declaration of a. DateTime is a value class not a ref class so it can't be null. 1st of all, while retriving "dates" into DateTime values, 1st you better change the . the datetime column in sql server can be insert a null value in C# code, and this. How to assign Null value to datetime variable using nullable I am getting a value from the textbox (I select a date) but, may be sometimes user. Inserting a null value to the DateTime Field in SQL Server is one of the most common issues giving various errors. Even if one enters null. Just call the nullable item and it will return the value if it exists. C# DateTime? returnDate = null; DateTime? d = www.doorway.ru; //Will. Every C# developer knows how to work with value types like int, double, boolean, char, and DateTime.
    [Show full text]
  • An Introduction to Lean
    An Introduction to Lean Jeremy Avigad Leonardo de Moura Gabriel Ebner and Sebastian Ullrich Version 1fc176a, updated at 2017-01-09 14:16:26 -0500 2 Contents Contents 3 1 Overview 5 1.1 Perspectives on Lean ............................... 5 1.2 Where To Go From Here ............................. 12 2 Defining Objects in Lean 13 2.1 Some Basic Types ................................ 14 2.2 Defining Functions ................................ 17 2.3 Defining New Types ............................... 20 2.4 Records and Structures ............................. 22 2.5 Nonconstructive Definitions ........................... 25 3 Programming in Lean 27 3.1 Evaluating Expressions .............................. 28 3.2 Recursive Definitions ............................... 30 3.3 Inhabited Types, Subtypes, and Option Types . 32 3.4 Monads ...................................... 34 3.5 Input and Output ................................ 35 3.6 An Example: Abstract Syntax ......................... 36 4 Theorem Proving in Lean 38 4.1 Assertions in Dependent Type Theory ..................... 38 4.2 Propositions as Types .............................. 39 4.3 Induction and Calculation ............................ 42 4.4 Axioms ...................................... 45 5 Using Automation in Lean 46 6 Metaprogramming in Lean 47 3 CONTENTS 4 Bibliography 48 1 Overview This introduction offers a tour of Lean and its features, with a number of examples foryou to play around with and explore. If you are reading this in our online tutorial system, you can run examples like the one below by clicking the button that says “try it yourself.” #check "hello world!" The response from Lean appears in the small window underneath the editor text, and also in popup windows that you can read when you hover over the indicators in the left margin. Alternatively, if you have installed Lean and have it running in a stand-alone editor, you can copy and paste examples and try them there.
    [Show full text]
  • Formats and Protocols for Continuous Data CD-1.1
    IDC Software documentation Formats and Protocols for Continuous Data CD-1.1 Document Version: 0.3 Document Edition: English Document Status: Final Document ID: IDC 3.4.3 Document Date: 18 December 2002 IDC Software documentation Formats and Protocols for Continuous Data CD-1.1 Version: 0.3 Notice This document was published December 2002 as Revision 0.3, using layout templates established by the IPT Group of CERN and IDC Corporate Style guidelines. This document is a re-casting of Revision 0.2published in December 2001 as part of the International Data Centre (IDC) Documentation. It was first published in July 2000 and was repub- lished electronically as Revision 0.1 in September 2001 and as Revision 0.2 in December 2001 to include minor changes (see the following Change Page for Revision 0.2). IDC documents that have been changed substantially are indicated by a whole revision number (for example, Revision 1). Trademarks IEEE is a registered trademark of the Institute of Electrical and Electronics Engineers, Inc. Motorola is a registered trademark of Motorola Inc. SAIC is a trademark of Science Applications International Corporation. Sun is a registered trademark of Sun Microsystems. UNIX is a registered trademark of UNIX System Labs, Inc. This document has been prepared using the Software Documentation Layout Templates that have been prepared by the IPT Group (Information, Process and Technology), IT Division, CERN (The European Laboratory for Particle Physics). For more information, go to http://framemaker.cern.ch/. page ii Final Abstract Version: 0.3 Abstract This document describes the formats and protocols of Continuous Data (CD-1.1), a standard to be used for transmitting continuous, time series data from stations of the International Monitoring System (IMS) to the International Data Centre (IDC) and for transmitting these data from the IDC to National Data Centers (NDCs).
    [Show full text]
  • Parts 43 and 45 Technical Specifications
    CFTC Technical Specification Parts 43 and 45 swap data reporting and public dissemination requirements September 17, 2020 Version 2.0 This Technical Specification document (“Tech Spec”) provides technical specifications for reporting swap data to Swap Data Repositories (SDRs) under parts 43 and 45. i TABLE OF CONTENTS INDEX OF DATA ELEMENTS ........................................................................................................................................................................................... III 1 INTRODUCTION ................................................................................................................................................................................................. VI 1.1 BACKGROUND .................................................................................................................................................................................................................. VI 1.2 STRUCTURE AND DESCRIPTION OF COLUMN HEADINGS ............................................................................................................................................................ VI 1.3 EXPLANATION OF DATA ELEMENT OR CATEGORY .................................................................................................................................................................... IX 1.4 UNIQUE PRODUCT IDENTIFIER (UPI) ....................................................................................................................................................................................
    [Show full text]
  • Datatypes in Isabelle/HOL
    Defining (Co)datatypes in Isabelle/HOL Jasmin Christian Blanchette, Lorenz Panny, Andrei Popescu, and Dmitriy Traytel Institut f¨urInformatik, Technische Universit¨atM¨unchen 5 December 2013 Abstract This tutorial describes how to use the new package for defining data- types and codatatypes in Isabelle/HOL. The package provides five main commands: datatype new, codatatype, primrec new, prim- corecursive, and primcorec. The commands suffixed by new are intended to subsume, and eventually replace, the corresponding com- mands from the old datatype package. Contents 1 Introduction3 2 Defining Datatypes5 2.1 Introductory Examples.....................5 2.1.1 Nonrecursive Types...................5 2.1.2 Simple Recursion.....................6 2.1.3 Mutual Recursion....................6 2.1.4 Nested Recursion.....................6 2.1.5 Custom Names and Syntaxes..............7 2.2 Command Syntax........................8 2.2.1 datatype new .....................8 2.2.2 datatype new compat ................ 11 2.3 Generated Constants....................... 12 2.4 Generated Theorems....................... 12 2.4.1 Free Constructor Theorems............... 13 1 CONTENTS 2 2.4.2 Functorial Theorems................... 15 2.4.3 Inductive Theorems................... 15 2.5 Compatibility Issues....................... 16 3 Defining Recursive Functions 17 3.1 Introductory Examples..................... 17 3.1.1 Nonrecursive Types................... 17 3.1.2 Simple Recursion..................... 17 3.1.3 Mutual Recursion.................... 18 3.1.4 Nested Recursion..................... 19 3.1.5 Nested-as-Mutual Recursion............... 20 3.2 Command Syntax........................ 20 3.2.1 primrec new ...................... 20 3.3 Recursive Default Values for Selectors............. 21 3.4 Compatibility Issues....................... 22 4 Defining Codatatypes 22 4.1 Introductory Examples..................... 22 4.1.1 Simple Corecursion................... 22 4.1.2 Mutual Corecursion..................
    [Show full text]