ML: the functional language

Download Report

Transcript ML: the functional language

ML: the metalanguage
Drew Wyborski
Programming Languages
Introduction
• Originally conceived to develop proof
tactics
• Automatically infers types
• Focus on developing programs through a
logical approach
• Used as the basis for several other
languages and dialects
Functional Programming
• Logical analysis is simple and easy
• No reassignment or modification of types
• Can prove assertions about a program
with ease
• Difficult to write programs that are illogical
• Lend themselves well of parallel execution
• Still retain all the useful components of a
traditional language
Functional vs. Imperative
•
•
•
•
•
Development Cycle
Development Language
Run-time System
FORTRAN, Pascal, C
ML, Hope, Lisp
Language Overview
• Call-by-value evaluation strategy
• Automatic memory allocation through
garbage collection
• Parametric polymorphism
• Static typing
• Exception handling
• Pattern matching
Development and Creation
• Developed by Robin Milner in 1973 at
Edinburgh University
• The goal behind ML
• The perfect language
Standard ML
•
•
•
•
Standard ML ’90 & Standard ML ‘97
Changes from original Edinburgh ML
Standard ML-New Jersey
Other popular versions
– Moscow ML
– ML Kit
– MLton
– PolyML
Characteristics
•
•
•
•
•
•
•
Safety through the type-checker
Structures and signatures
Flexibility of functions
Call-by-value evaluation
Polymorphism
Compile-time type checking
Type inference
Characteristics
•
•
•
•
•
•
•
•
Garbage collection
Exemption handling
Immutable data types
Updating references
Abstraction
Parametric modules
Formal definition
Proof of completeness
Data Type/Operators
• Operators and types similar to C++/Java
– int, string, bool and real remain the same
– Operators have slight differences
• Additional Boolean types are included
showing the rational/logical basis
– andalso & orelse
Syntax
• Input is placed into user’s implementation
• Machine responds with result of
expression
• Specified layout for entry and output
– 3 + 4;
– val it = 7 : int
• If an error is made in entry, the machine
responds with an appropriate error
• The unit data type
Definitions
• Global constants
– val PI = 3.4;
– Help increase readability
• Functions
– fun succ n = n+1;
– val succ = fn : int  int
• Extensions
– if…then…else functions
– Multiple input/output functions