1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Cs784(TK)1 Semantics of Procedures and Scopes. Kinds of Scope Static or Lexical scope –determined by structure of program –Scheme, C++, Java, and many.
CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
Type Checking.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
1 Functional Programming and ML. 2 What’s wrong with Imperative Languages? State State Introduces context sensitivity Introduces context sensitivity Harder.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Introduction To System Analysis and design
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
 The design of the imperative languages is based directly on the von Neumann architecture  Efficiency is the primary concern  Low-level specifications:
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
CSE S. Tanimoto Introduction to ML 1 Introduction to ML History Special features Interacting with ML ML’s basic types ML’s composite types Math.
Chapter 9: Functional Programming in a Typed Language.
Compiling Functional Programs Mooly Sagiv Chapter 7
Programming Domains 1.Scientific Applications Typically, scientific applications have simple data structures but require large numbers of floating-point.
PZ03EX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03EX - ML Programming Language Design and Implementation.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
COMP313A Functional Programming (1)
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
1-1 An Introduction to Functional Programming Sept
Error Example - 65/4; ! Toplevel input: ! 65/4; ! ^^ ! Type clash: expression of type ! int ! cannot have type ! real.
CSE 130 : Spring 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 5: Functions and Closures.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
BY: JAKE TENBERG & CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.
Cs776 (Prasad)L2HOF1 Higher-Order Functions. cs776 (Prasad)L2HOF2 Higher-Order Functions A function that takes a function as argument and/or returns a.
Functional Programming
Programming Languages and Compilers (CS 421)
Functional Programming
ML: a quasi-functional language with strong typing
ML Programming Language Design and Implementation (4th Edition)
Names, Binding, and Scope
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
The Metacircular Evaluator
Closure Closure binds a first-class function and a lexical environment together This is a complex topic, so we will build up our understanding of it we.
Programming Languages 2nd edition Tucker and Noonan
CSE S. Tanimoto Introduction to ML
CSE S. Tanimoto Introduction to ML
CSE S. Tanimoto Introduction to ML
CSE 341 Lecture 11 b closures; scoping rules
CSE S. Tanimoto Lambda Calculus
CSE S. Tanimoto Introduction to ML
Chapter 15 Functional Programming 6/1/2019.
Drew Wyborski Programming Languages
Presentation transcript:

1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University of North Carolina, Asheville Fun max (x,y) = if x > y then x else y;

2 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 An Overview of ML n Description u ML is a high level functional programming language similar to LISP, Prolog, and Hope. u ML is further differentiated by a strong and static type system, type inference, and garbage collection. u ML was the first language to include statically checked polymorphic typing. n History u ML was created as a metalanguage for the Edinburgh LCF proof assistant in u It has since developed into its own language, hence the acronymn ML no longer is a relevant descriptor of the language.

3 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML: An Example Program n ML Computation: Calculation of Expressions u ML is a robust functional language that combines many of the features of other programming languages we have studied in this course. u The unit of evaluation in ML is the expression. Every expression has a type, possibly a value, and may or may not cause an effect.  ML also limits defined functions to only take a single parameter, however, this parameter may be a tuple, or a ‘unit’ (the empty set). u ML is typically run in an interpretive manner.  (ML expression): fun average (x, y) = (x +y) / 2.0;  (User input): -average (5, 7); F (Resulting values): - val it = 6 : int

4 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML As a Functional Language: ML is more Powerful! n ML is Powerful: u ML has many of the attributes that you would expect in a functional language like Scheme or LISP, such as: F Computation by expression rather than execution of instruction F Declarative programming abstraction F Lambda calculus function methodology u Yet ML incorporates other features not usually found in functional languages, such as: F Exception Handling F Garbage Collection F User defined Abstract Data Types F Strong and type handling and type inference

5 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML As a Functional Language: Further Details n ML exibits referential transparency u Variable assignment is a ‘once only’ operation. u Variable values do not change once assigned. u Referential transparency greatly increases the ability of a program to be quantitatively analyzed, used as a proof, and debugged. n ML variables are statically scoped u ML’s variables are entirely local to a called function u Variables are bound at run-time. Compiling is not often used. u Global variables don’t exist. Neither do instances of an object as might be found in other languages supporting object abstractions. n ML can handle many of the more interesting data types u Lists, Real Numbers, User defined ADTs

6 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Functions: Extending the Functional Languages n ML functions may be of the highest order u ML uses aggressive type inference methods u ML has few standard data types, but all are extensible u Even Functions may define other Functions!, as in this example: Fun try (a, x) = a x; > val try = fn : (‘a -> ‘b) * ‘a -> ‘b Try (hd, [1,2,3]; >val it = 1 : int Try (t1, [1,2,3]); > val it = [2, 3] : int list u Such higher order functions have great utility and are part of the attraction of a Functional language.

7 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Functions: Extending the Functional Languages n ML supports Currying and Mapping: u Higher order functions may even embed arguments into the definition of a new function.This is called ‘Currying’. u For Example: F Fun incr x y = x + y; F Val incr = fn : int -> int -> int F Incr 5 3; F Vali it = 8 : int F (incr 5) 3; F Val it = 8 : int F Val incr5 = incr 5; F Val incr5 = fn : int -> int F Incr5 3; F Val it = 8 : int

8 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Polymorphism: n ML broke programming ground with strong polymorphism: u ML uses the term polymorphism to refer to the attribute of a function to handle more than one type of parameter. List is a good example. It works with any list of any type of elements. F The list functions are similar to Scheme, only cleaner. u The ML conception of polymorphism is different than the idea of method overloading that the term polymorphism can also signify. We do not mean merely having two or more functions with the same name. u ML functions are polymorphic if they contain only polymorphic functions and operators. For example: F Fun revPair (x, y) = (y, x)

9 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Functions: Local Variables are ‘Let’ into a Function n ML allows local variables in a function. u The syntax for local variables follows the pattern : F Let………..in…………end u As we see in the following example: Fun circleData (radius) = Let Val pi = Val circumference = two * pi * radius; Fun area radius = pi * radius * radius In (circumference, area (radius)) End;

10 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Flow Control: The Function Stack n Flow Control is an Interpretive Process F ML parses each line as an ML expression. F ML can use files and libraries, much like scheme. F ML performs I./O with simple grace, for example : fun copyFile (inputFileName, outputFileName) = Let Val inFile = openIn inputFileName; Val outFile = openOut outputFileName In ( output (outFile, input inFile); flushOut outFile; closeOut outFile ) End; F ML has been ported to many graphical windowing environments, such as the unix/linux x-windowing system.

11 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML Handles Exceptions ML supports user-defined error flow control u Such exception handling makes ML an attractive alternative to other Functional languages where this is not possible

12 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 Conclusion: ML is a little known giant n ML should be better known and used: u ML is highly orthogonal. Most functions that work with one type of parameter will work with any parameter. ML has good internal type checking mechanisms which are applied to every evaluated expression consistently. u Because ML allows for recursion, nested constructs, list functions, and polymorphism, it is considered a highly abstracted language, capable of implementing the most complex of programming tasks with the most ease for the programmer.

13 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 Conclusion: ML is a popular outcast n ML in their words: u “ML has made significant inroads into the computer science educational and research communities. The exposure of the type mechanism at the source language level is a feature not available in other widely used languages. However, commercial applications of ML programs are few, and so far it remains mostly a vehicle for computer science research and educational use.” (That old book). u “…This may be because there are not enough…” F Gentle intro to ML: readers comments