ML (Meta Language) a brief introduction - PowerPoint PPT Presentation

About This Presentation
Title:

ML (Meta Language) a brief introduction

Description:

Alex Proctor and Brian Lee. For CSCI 431 at the University of North Carolina, Asheville ... Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002. ML Flow ... – PowerPoint PPT presentation

Number of Views:806
Avg rating:3.0/5.0
Slides: 14
Provided by: chuc112
Learn more at: https://www.cs.unca.edu
Category:

less

Transcript and Presenter's Notes

Title: ML (Meta Language) a brief introduction


1
ML (Meta Language)a brief introduction
Fun max (x,y) if x gt y then x else y
  • Alex Proctor and Brian Lee
  • For CSCI 431 at the University of North Carolina,
  • Asheville

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

3
ML An Example Program
  • ML Computation Calculation of Expressions
  • ML is a robust functional language that combines
    many of the features of other programming
    languages we have studied in this course.
  • 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).
  • ML is typically run in an interpretive manner.
  • (ML expression) fun average (x, y) (x y) /
    2.0
  • (User input) - average (5, 7)
  • (Resulting values) - val it 6 int

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

5
ML As a Functional Language Further Details
  • ML exibits referential transparency
  • Variable assignment is a once only operation.
  • Variable values do not change once assigned.
  • Referential transparency greatly increases the
    ability of a program to be quantitatively
    analyzed, used as a proof, and debugged.
  • ML variables are statically scoped
  • MLs variables are entirely local to a called
    function
  • Variables are bound at run-time. Compiling is not
    often used.
  • Global variables dont exist. Neither do
    instances of an object as might be found in other
    languages supporting object abstractions.
  • ML can handle many of the more interesting data
    types
  • Lists, Real Numbers, User defined ADTs

6
ML Functions Extending the Functional Languages
  • ML functions may be of the highest order
  • ML uses aggressive type inference methods
  • ML has few standard data types, but all are
    extensible
  • Even Functions may define other Functions!, as in
    this example
  • Fun try (a, x) a x
  • gt val try fn (a -gt b) a -gt b
  • Try (hd, 1,2,3
  • gtval it 1 int
  • Try (t1, 1,2,3)
  • gt val it 2, 3 int list
  • Such higher order functions have great utility
    and are part of the attraction of a Functional
    language.

7
ML Functions Extending the Functional Languages
  • ML supports Currying and Mapping
  • Higher order functions may even embed arguments
    into the definition of a new function.This is
    called Currying.
  • For Example
  • Fun incr x y x y
  • Val incr fn int -gt int -gt int
  • Incr 5 3
  • Vali it 8 int
  • (incr 5) 3
  • Val it 8 int
  • Val incr5 incr 5
  • Val incr5 fn int -gt int
  • Incr5 3
  • Val it 8 int

8
ML Polymorphism
  • ML broke programming ground with strong
    polymorphism
  • 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.
  • The list functions are similar to Scheme, only
    cleaner.
  • 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.
  • ML functions are polymorphic if they contain only
    polymorphic functions and operators. For example
  • Fun revPair (x, y) (y, x)

9
ML Functions Local Variables are Let into a
Function
  • ML allows local variables in a function.
  • The syntax for local variables follows the
    pattern
  • Let..inend
  • As we see in the following example
  • Fun circleData (radius)
  • Let
  • Val pi 3.1415926536
  • Val circumference two pi radius
  • Fun area radius pi radius radius
  • In
  • (circumference, area (radius))
  • End

10
ML Flow Control The Function Stack
  • Flow Control is an Interpretive Process
  • ML parses each line as an ML expression.
  • ML can use files and libraries, much like scheme.
  • 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
  • ML has been ported to many graphical windowing
    environments, such as the unix/linux x-windowing
    system.

11
ML Handles Exceptions
  • ML supports user-defined error flow control
  • Such exception handling makes ML an attractive
    alternative to other Functional languages where
    this is not possible

12
Conclusion ML is a little known giant
  • ML should be better known and used
  • 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.
  • 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
Conclusion ML is a popular outcast
  • ML in their words
  • 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).
  • This may be because there are not enough
  • Gentle intro to ML readers comments
Write a Comment
User Comments (0)
About PowerShow.com