An Overview of Standard ML M

Total Page:16

File Type:pdf, Size:1020Kb

An Overview of Standard ML M CMSC 22100/32100: Programming Languages An Overview of Standard ML M. Blume October 2, 2008 Contents 1 What is SML 2 2 Integers, reals, booleans 2 3 Variables 3 4 Constructing new types 4 4.1 Option type . 4 4.2 List type . 4 4.3 Tuples . 5 4.4 Records . 6 4.5 Data Types . 6 5 Functions 9 5.1 Function values and function definitions . 9 5.2 Function application . 10 5.3 Curried function definitions . 10 6 Other types 11 6.1 The unit type ............................... 11 6.2 References|the ref type ......................... 11 6.3 Text|the types char and string ..................... 11 7 Block structure 12 7.1 Simultaneous bindings and mutual recursion . 13 8 Patterns and pattern matching 14 8.1 Examples . 16 9 Other language features 18 9.1 Polymorphism . 18 9.2 Modules . 18 9.3 Exceptions . 21 9.4 Infix declarations . 21 10 Using Files 21 10.1 Function use ................................ 21 10.2 A note on polymorphism and type inference . 22 10.3 Generativity of datatype definitions . 22 10.4 CM | the SML/NJ compilation manager . 23 1 A Reserved words 23 B Pre-defined infix operators 24 C Other restricted identifiers 24 1 What is SML Standard ML is a strongly typed, impure, strict functional language. Strongly typed: Every value, expression in the language has a type (int, real, bool etc.). The compiler rejects a program that does not conform to the type system of the language. Functional: Each expression evaluates to a value. Some of these values are functions. In fact, every function in ML is a value. Like other values, functions can be bound to variables, passed as arguments to other func- tions, returned as values from function calls, and stored in data structures. Impure: Unlike in other functional languages such as Haskell, the evaluation of expressions in ML can incur side-effects, e.g., assignment to locations within mutable data structures or I/O. Strict: Unlike \lazy" languages such as Haskell, arguments to ML functions are evaluated before the function call is performed. This means that if one of the arguments loops forever, then so will the entire program, regardless of whether or not the function actually needed that argument. Similarly, all side-effects caused by the evaluation of the arguments occur before any side-effects caused by the evaluation of the function body. In this class, we will use the SML/NJ compiler. SML/NJ generates reason- ably fast executable code, although some other compilers, e.g., MLton, outper- form it on a regular basis. However, SML/NJ can be used interactively and comes with a mature programming environment. (Some people use SML/NJ for development and use MLton to speed up the final version. However, in this class, runtime performance will not be an issue.) 2 Integers, reals, booleans Among the built-in data types are the following: int, real, bool, 'a option, etc. Standard ML calls the type of floating points numbers real.1 Here are some examples. $ sml Standard ML of New Jersey v110.68 [built: Mon Sep 8 13:47:59 2008] - (* Integers: *) 1This is a misnomer; they are really finite precision numbers. 2 - 1; val it = 1 : int - 2; val it = 2 : int - 1+2; val it = 3 : int - - (* Reals: *) - 1.0; val it = 1.0 : real - 2.0; val it = 2.0 : real - Math.sqrt(3.0*3.0+4.0*4.0); [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] val it = 5.0 : real - (* Booleans: *) - false; val it = false : bool - true; val it = true : bool - if true then 1 else 2; val it = 1 : int Some notes: • Comments in Standard ML are enclosed within comment brackets: (* ... *). Comments are nestable. • Many library functions such as Math.sqrt are automatically loaded by the SML/NJ interactive system on an on-demand basis. This is what accounts for the [autoloading ... done] sequence of messages. 3 Variables Variables in Standard ML are identifiers that name values. Once a binding for a variable is established, the variable continues to name the same value until it goes out of scope. In other words, Standard ML variables are immutable. Imperative programming with assignment, while possible using reference val- ues (see below), it is not encouraged and cannot be done using variables alone. Assignment to variables can usually be avoided by writing iterative algo- rithms in recursive style. In this style, instead of changing the value of a vari- able one simply establishes a new binding. The new binding can use the same identifier, in which case the old binding will be shadowed and go out of scope. As an example, consider the following iterative version of the factorial func- tion, written in tail-recursive style: 3 - fun fac_loop (n, f) = if n = 0 then f else fac_loop (n-1, f*n); val fac_loop = fn : int * int -> int - fun fac n = fac_loop (n, 1); val fac = fn : int -> int - fac 10; val it = 3628800 : int 4 Constructing new types ML has a variety of built-in type constructors, and programmers can add to that variety by defining their own. A type constructor maps a sequence of types to another type. The length of the argument sequence is called the arity of the type constructor. The names of \ordinary" types, e.g., int, bool, real, and so on are actually type constructors of arity 0. When forming types, the type arguments precede the name of the constructor.2 4.1 Option type One of the predefined type constructors in Standard ML is option. It gives rise to the family of option types. Example: Values of type int option come in two varieties: There is the singleton value NONE or the set of values of the form SOME i where i an integer. In general, types of the form t option are used to describe situations where there may or may not be a value of type t. For example, the library function Int.fromString takes a string argument and returns an int option, using NONE to indicate that the argument could not be parsed as an integer. - NONE; val it = NONE : 'a option - SOME 1; val it = SOME 1 : int option - SOME 1.0; val it = SOME 1.0 : real option - SOME false; val it = SOME false : bool option The option type is really a datatype (see below) defined by: datatype 'a option = NONE | SOME of 'a 4.2 List type Another predefined type constructor in Standard ML is list. A type t list contains values that are finite lists whose elements are values of type t. The 2If there is more than one, the arguments are given as a comma-separated list, enclosed in parentheses. 4 empty list is called nil. The keyword nil is special in that it is interchangeable with the notation []. A non-empty list consists of a head element and a tail list (of the same type). If h is the head and t is the tail, then the entire list is h :: t. The infix constructor :: is sometimes pronounced \cons." It associates to the right. A k-element list x1 :: ··· :: xk :: nil can alternatively be written [x1, :::, xk]. - nil; val it = [] : 'a list - 1 :: nil; val it = [1] : int list - true :: false :: nil; val it = [true,false] : bool list - [1.0,2.0,4.0]; val it = [1.0,2.0,4.0] : real list The list type is essentially a datatype (see below) defined by: datatype 'a list = nil | :: of 'a * 'a list However, to be precise, one must also declare :: as an infix operator and estab- lish the alternative syntax using square brackets. The former would be possible using a Standard ML infix declaration (actually, since we need right associativ- ity, it would be an infixr declaration), but the latter is built-in syntax|which is why the list type itself must be built-in and cannot be defined from first principles. 4.3 Tuples The built-in type constructor *, which is written in infix notation and may be repeated as in int * real * bool to form arbitrary n-ary tuple type con- structors, produces types that correspond to cartesian products of other types. The values inhabiting these types are called tuples and are written as comma- separated sequences enclosed in round parentheses. - (1, 2); val it = (1,2) : int * int - (1.0, 2.0); val it = (1.0,2.0) : real * real - (1, 2.0, true, NONE); val it = (1,2.0,true,NONE) : int * real * bool * 'a option The notation #i where i is an integer literal greater or equal than 1, speci- fying a position, can be used to project from tuples. However, it is often more convenient to get at the elements of a tuple by pattern matching (see below). 5 - #1 (1, 2.0); val it = 1 : int - #2 (1, 2.0); val it = 2.0 : real 4.4 Records Records generalize tuples by making it possible to give names (labels) to fields instead of relying on positional information. (In fact, Standard ML defines tuples to be special cases of records where the labels are numeric and form an uninterrupted sequence from 1 to some natural number n.) Projection from records uses the notation #l where l is the label name. - val r = { a = 1.0, b = true, c = {a = 3.0}, d = fn x => x}; val r = {a=1.0,b=true,c={a=3.0},d=fn} : {a:real, b:bool, c:{a:real}, d:'a -> 'a} - #a (#c r); val it = 3.0 : real - (#d r) 1; val it = 1 : int As shown in the examples above, record types have the form fl1:t1; : : : ;ln:tng where the li are the labels and the ti are the corresponding types of individual record fields.
Recommended publications
  • Type-Safe Multi-Tier Programming with Standard ML Modules
    Experience Report: Type-Safe Multi-Tier Programming with Standard ML Modules Martin Elsman Philip Munksgaard Ken Friis Larsen Department of Computer Science, iAlpha AG, Switzerland Department of Computer Science, University of Copenhagen, Denmark [email protected] University of Copenhagen, Denmark [email protected] kfl[email protected] Abstract shared module, it is now possible, on the server, to implement a We describe our experience with using Standard ML modules and module that for each function responds to a request by first deseri- Standard ML’s core language typing features for ensuring type- alising the argument into a value, calls the particular function and safety across physically separated tiers in an extensive web applica- replies to the client with a serialised version of the result value. tion built around a database-backed server platform and advanced Dually, on the client side, for each function, the client code can client code that accesses the server through asynchronous server serialise the argument and send the request asynchronously to the requests. server. When the server responds, the client will deserialise the re- sult value and apply the handler function to the value. Both for the server part and for the client part, the code can be implemented in 1. Introduction a type-safe fashion. In particular, if an interface type changes, the The iAlpha Platform is an advanced asset management system programmer will be notified about all type-inconsistencies at com- featuring a number of analytics modules for combining trading pile
    [Show full text]
  • Understanding the Syntactic Rule Usage in Java
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by UCL Discovery Understanding the Syntactic Rule Usage in Java Dong Qiua, Bixin Lia,∗, Earl T. Barrb, Zhendong Suc aSchool of Computer Science and Engineering, Southeast University, China bDepartment of Computer Science, University College London, UK cDepartment of Computer Science, University of California Davis, USA Abstract Context: Syntax is fundamental to any programming language: syntax defines valid programs. In the 1970s, computer scientists rigorously and empirically studied programming languages to guide and inform language design. Since then, language design has been artistic, driven by the aesthetic concerns and intuitions of language architects. Despite recent studies on small sets of selected language features, we lack a comprehensive, quantitative, empirical analysis of how modern, real-world source code exercises the syntax of its programming language. Objective: This study aims to understand how programming language syntax is employed in actual development and explore their potential applications based on the results of syntax usage analysis. Method: We present our results on the first such study on Java, a modern, mature, and widely-used programming language. Our corpus contains over 5,000 open-source Java projects, totalling 150 million source lines of code (SLoC). We study both independent (i.e. applications of a single syntax rule) and dependent (i.e. applications of multiple syntax rules) rule usage, and quantify their impact over time and project size. Results: Our study provides detailed quantitative information and yields insight, particularly (i) confirming the conventional wisdom that the usage of syntax rules is Zipfian; (ii) showing that the adoption of new rules and their impact on the usage of pre-existing rules vary significantly over time; and (iii) showing that rule usage is highly contextual.
    [Show full text]
  • S-Algol Reference Manual Ron Morrison
    S-algol Reference Manual Ron Morrison University of St. Andrews, North Haugh, Fife, Scotland. KY16 9SS CS/79/1 1 Contents Chapter 1. Preface 2. Syntax Specification 3. Types and Type Rules 3.1 Universe of Discourse 3.2 Type Rules 4. Literals 4.1 Integer Literals 4.2 Real Literals 4.3 Boolean Literals 4.4 String Literals 4.5 Pixel Literals 4.6 File Literal 4.7 pntr Literal 5. Primitive Expressions and Operators 5.1 Boolean Expressions 5.2 Comparison Operators 5.3 Arithmetic Expressions 5.4 Arithmetic Precedence Rules 5.5 String Expressions 5.6 Picture Expressions 5.7 Pixel Expressions 5.8 Precedence Table 5.9 Other Expressions 6. Declarations 6.1 Identifiers 6.2 Variables, Constants and Declaration of Data Objects 6.3 Sequences 6.4 Brackets 6.5 Scope Rules 7. Clauses 7.1 Assignment Clause 7.2 if Clause 7.3 case Clause 7.4 repeat ... while ... do ... Clause 7.5 for Clause 7.6 abort Clause 8. Procedures 8.1 Declarations and Calls 8.2 Forward Declarations 2 9. Aggregates 9.1 Vectors 9.1.1 Creation of Vectors 9.1.2 upb and lwb 9.1.3 Indexing 9.1.4 Equality and Equivalence 9.2 Structures 9.2.1 Creation of Structures 9.2.2 Equality and Equivalence 9.2.3 Indexing 9.3 Images 9.3.1 Creation of Images 9.3.2 Indexing 9.3.3 Depth Selection 9.3.4 Equality and Equivalence 10. Input and Output 10.1 Input 10.2 Output 10.3 i.w, s.w and r.w 10.4 End of File 11.
    [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]
  • Sugarj: Library-Based Syntactic Language Extensibility
    SugarJ: Library-based Syntactic Language Extensibility Sebastian Erdweg, Tillmann Rendel, Christian Kastner,¨ and Klaus Ostermann University of Marburg, Germany Abstract import pair.Sugar; Existing approaches to extend a programming language with syntactic sugar often leave a bitter taste, because they cannot public class Test f be used with the same ease as the main extension mechanism private (String, Integer) p = ("12", 34); of the programming language—libraries. Sugar libraries are g a novel approach for syntactically extending a programming Figure 1. Using a sugar library for pairs. language within the language. A sugar library is like an or- dinary library, but can, in addition, export syntactic sugar for using the library. Sugar libraries maintain the compos- 1. Introduction ability and scoping properties of ordinary libraries and are Bridging the gap between domain concepts and the imple- hence particularly well-suited for embedding a multitude of mentation of these concepts in a programming language is domain-specific languages into a host language. They also one of the “holy grails” of software development. Domain- inherit self-applicability from libraries, which means that specific languages (DSLs), such as regular expressions for sugar libraries can provide syntactic extensions for the defi- the domain of text recognition or Java Server Pages for the nition of other sugar libraries. domain of dynamic web pages have often been proposed To demonstrate the expressiveness and applicability of to address this problem [31]. To use DSLs in large soft- sugar libraries, we have developed SugarJ, a language on ware systems that touch multiple domains, developers have top of Java, SDF and Stratego, which supports syntactic to be able to compose multiple domain-specific languages extensibility.
    [Show full text]
  • Four Lectures on Standard ML
    Mads Tofte March Lab oratory for Foundations of Computer Science Department of Computer Science Edinburgh University Four Lectures on Standard ML The following notes give an overview of Standard ML with emphasis placed on the Mo dules part of the language The notes are to the b est of my knowledge faithful to The Denition of Standard ML Version as regards syntax semantics and terminology They have b een written so as to b e indep endent of any particular implemen tation The exercises in the rst lectures can b e tackled without the use of a machine although having access to an implementation will no doubt b e b enecial The pro ject in Lecture presupp oses access to an implementation of the full language including mo dules At present the Edinburgh compiler do es not fall into this category the author used the New Jersey Standard ML compiler Lecture gives an introduction to ML aimed at the reader who is familiar with some programming language but do es not know ML Both the Core Language and the Mo dules are covered by way of example Lecture discusses the use of ML mo dules in the development of large programs A useful metho dology for programming with functors signatures and structures is presented Lecture gives a fairly detailed account of the static semantics of ML mo dules for those who really want to understand the crucial notions of sharing and signature matching Lecture presents a one day pro ject intended to give the student an opp ortunity of mo difying a nontrivial piece of software using functors signatures and structures
    [Show full text]
  • Syntactic Sugar Programming Languages' Constructs - Preliminary Study
    ICIT 2011 The 5th International Conference on Information Technology Syntactic Sugar Programming Languages' Constructs - Preliminary Study #1 #2 Mustafa Al-Tamim , Rashid Jayousi Department of Computer Science, Al-Quds University, Jerusalem, Palestine [email protected] 00972-59-9293002 [email protected] 00972-52-7456731 ICIT 2011 The 5th International Conference on Information Technology Syntactic Sugar Programming Languages' Constructs - Preliminary Study #1 #2 Mustafa Al-Tamim , Rashid Jayousi Department of Computer Science, Al-Quds University, Jerusalem, Palestine [email protected] [email protected] Abstract— Software application development is a daily task done syntax and help in making it more readable, easier to write, by developers and code writer all over the world. Valuable less syntax errors and less ambiguous. portion of developers’ time is spent in writing repetitive In this research, we proposed new set of syntactic sugar keywords, debugging code, trying to understand its semantic, constructs that can be composed by a mixture of existing and fixing syntax errors. These tasks become harder when no constructs obtained from some programming languages in integrated development environment (IDE) is available or developers use remote access terminals like UNIX and simple addition to syntactic enhancements suggested by us. Through text editors for code writing. Syntactic sugar constructs in our work as software developer, team leaders, and guiding programming languages are found to offer simple and easy many students in their projects, we noticed that developers syntax constructs to make developers life easier and smother. In write a lot of repetitive keywords in specific parts of code like this paper, we propose a new set of syntactic sugar constructs, packages calling keywords, attributes access modifiers, code and try to find if they really can help developers in eliminating segments and building blocks’ scopes determination symbols syntax errors, make code more readable, more easier to write, and others.
    [Show full text]
  • Compiler Construction E Syntactic Sugar E
    Compiler Construction e Syntactic sugar E Compiler Construction Syntactic sugar 1 / 16 Syntactic sugar & Desugaring Syntactic Sugar Additions to a language to make it easier to read or write, but that do not change the expressiveness Desugaring Higher-level features that can be decomposed into language core of essential constructs ) This process is called ”desugaring”. Compiler Construction Syntactic sugar 2 / 16 Pros & Cons for syntactic sugar Pros More readable, More writable Express things more elegantly Cons Adds bloat to the languages Syntactic sugar can affect the formal structure of a language Compiler Construction Syntactic sugar 3 / 16 Syntactic Sugar in Lambda-Calculus The term ”syntactic sugar” was coined by Peter J. Landin in 1964, while describing an ALGOL-like language that was defined in term of lambda-calculus ) goal: replace λ by where Curryfication λxy:e ) λx:(λy:e) Local variables let x = e1 in e2 ) (λx:e2):e1 Compiler Construction Syntactic sugar 4 / 16 List Comprehension in Haskell qs [] = [] qs (x:xs) = qs lt_x ++ [x] ++ qs ge_x where lt_x = [y | y <- xs, y < x] ge_x = [y | y <- xs, x <= y] Compiler Construction Syntactic sugar 5 / 16 List Comprehension in Haskell Sugared [(x,y) | x <- [1 .. 6], y <- [1 .. x], x+y < 10] Desugared filter p (concat (map (\ x -> map (\ y -> (x,y)) [1..x]) [1..6] ) ) where p (x,y) = x+y < 10 Compiler Construction Syntactic sugar 6 / 16 Interferences with error messages ”true” | 42 standard input:1.1-6: type mismatch condition type: string expected type: int function _main() = ( (if "true" then 1 else (42 <> 0)); () ) Compiler Construction Syntactic sugar 7 / 16 Regular Unary - & and | Beware of ( exp ) vs.
    [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]
  • A Separate Compilation Extension to Standard ML
    A Separate Compilation Extension to Standard ML David Swasey Tom Murphy VII Karl Crary Robert Harper Carnegie Mellon {swasey,tom7,crary,rwh}@cs.cmu.edu Abstract The goal of this work is to consolidate and synthesize previ- We present an extension to Standard ML, called SMLSC, to support ous work on compilation management for ML into a formally de- separate compilation. The system gives meaning to individual pro- fined extension to the Standard ML language. The extension itself gram fragments, called units. Units may depend on one another in a is syntactically and conceptually very simple. A unit is a series of way specified by the programmer. A dependency may be mediated Standard ML top-level declarations, given a name. To the current by an interface (the type of a unit); if so, the units can be compiled top-level declarations such as structure and functor we add an separately. Otherwise, they must be compiled in sequence. We also import declaration that is to units what the open declaration is to propose a methodology for programming in SMLSC that reflects structures. An import declaration may optionally specify an inter- code development practice and avoids syntactic repetition of inter- face for the unit, in which case we are able to compile separately faces. The language is given a formal semantics, and we argue that against that dependency; with no interface we must compile incre- this semantics is implementable in a variety of compilers. mentally. Compatibility with existing compilers, including whole- program compilers, is assured by making no commitment to the Categories and Subject Descriptors D.3.3 [Programming Lan- precise meaning of “compile” and “link”—a compiler is free to guages]: Language Constructs and Features—Modules, pack- limit compilation to elaboration and type checking, and to perform ages; D.3.1 [Programming Languages]: Formal Definitions and code generation as part of linking.
    [Show full text]