Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
94 views

ML Programming Languages

ML is a functional programming language developed in the 1970s at the University of Edinburgh. It is strongly typed, with type checking done during compilation. Key features include union types, parametric polymorphism, recursion, exceptions, and lists. Functions are defined using the fun keyword and patterns can be matched using pipes. Common operations include arithmetic, conditionals, concatenation, and basic data types like int, bool, real, char, and strings.

Uploaded by

soundarpandiyan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

ML Programming Languages

ML is a functional programming language developed in the 1970s at the University of Edinburgh. It is strongly typed, with type checking done during compilation. Key features include union types, parametric polymorphism, recursion, exceptions, and lists. Functions are defined using the fun keyword and patterns can be matched using pipes. Common operations include arithmetic, conditionals, concatenation, and basic data types like int, bool, real, char, and strings.

Uploaded by

soundarpandiyan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

• Primarily a functional programming language.

• ML is a strongly typed language, need not declare data type


• Developed in late 1970 as part of system for providing correctness of programs
• Developed at university of Edinburgh in UK
• By a team headed by Robin Milner and Michael Gordon
• Influenced the creation of Miranda, Haskell, Cyclone, Nemerle, C++, Clojure

Important features are


• Union
• Conflict
• Recursive
• Parametric module
• Exceptional handling mechanism
• Polymorphism data types and function
• In ML there are two phases of program execution consisting of static phase for approval of program
correctness & dynamic phase that is program execution.
• No use of parenthesis
• The syntax is strongly typed, allowing type of every expression to determined before execution and
types to be checked for consistency

Principles of ML
• ML expressions must be followed by a semicolon
• ML responds for any definition through the following primitives
o val stands for value
o it the variable ‘it’ stands for definition value
o : represent the association of value with a type

Operator:
• Arithmetic: +-*/, mod for remainder of integer
• / is for division of real numbers and div for division of integers
• string concatenation ^
• Conditional operator = ,>,<,>=,<=,<>
• ‘and also’ for logical and & ‘or else’ for logical or

Primitive Data types


int, boolean, real, character and string

Structured data types or derived


List and Tuple
Tuple is a group of n values
List is formed by taking variables of same datatype.

Functions
Syntax : fun function_name (Parameter list) = function body;

Eg; fun number(x : int)= x+5;


Factorial function:
fun fact n = let
fun fac 0 = 1
| fac n = n * fac (n - 1)
in
if (n < 0) then raise Fail "negative argument"
else fac n
end

List reverse function:


The following function not only reverses the list but also returns the reversed list.
fun reverse xs = let
fun rev nil acc = acc
| rev (hd::tl) acc = rev tl (hd::acc)
in
rev xs nil
end

You might also like