Programming Language A study note (a)

Source: Internet
Author: User

SML (i)

1. ML is a functional programming language with a theoretical basis for λ calculus.

2. Variable declaration

val x = e;

Standard types: cell (unit), Boolean (bool), integer (int), string, real (real), tuple (tuple), records (record), list

1) Negative numbers indicate that the minus sign is denoted by "~", and 1 means "to";

2) string: A sequence of characters between double quotation marks;

3) Real numbers: floating-point numbers in which other languages are expressed as double;

4) List: "[]" denotes empty list,list example: [1, 4, 9, 25],list, data types in the requirements of the same, can be nested;

5) Tuple: comma-delimited data elements in parentheses, can be nested, tuple data types can be inconsistent, for example: (A, 9);

6) Record: The values and types of records are written in {}, for example: {first:int, middle:int, last:int};

1

Meta-group

List

Recording

Brackets

()

[]

{}

Element type

can be different

Must be the same

can be different

Length

Fixed length

Variable length

Variable length

Type-expression

< element type > expression with * connection

< element types > List

{Record Name: < element type;}

3. Using the program file: Use "FOO.SML";

4. Function definition

The type of the function in SML is determined by his defined domain and range.

Sml

C language

Fun Division (X:int, Y:int) =

X div y

int division (int x, int y)

{

return x/y;

}

5. Tuple Data references

Tuple Pr:int * bool = #1 PR tuple first element, int type; #2 PR tuple second element, bool type;

6. List data references

HD, List header elements, lists other than TL,HD elements;

7. Let expression: Let B1 B2 ... bn in E end

B1 B2 ... bn can be a variable declaration, function definition, etc., E is an expression

8. Conditional expression: If E1 then E2 else E3

E1, E2, E3 are expressions, E2 and E3 require the same data type;

9. NONE, some and Valof

Key words

Evaluate

TYPE

' A

Any type

' A list

After any type of LIST;HD type is determined, the list type is fixed

NONE

NONE is a option value "carrying nothing" whereas

' A option

SOME E

SOME e evaluates e to a value V and becomes the option carrying the one value v.

T option if E has type T.

NULL, Issome

Null to see if a list is empty and we have issome which evaluates to False if its argumentis NONE.

Valof

Get the value carried by SOME (raising a exception for NONE)

10. Operators

Arithmetic plus, minus, multiply, divide: + 、-、 *, div (int),/(real type)

Logical operations and, or, non, equal, unequal, greater than, less than, greater than or equal to, less than or equal to: AndAlso, OrElse, not, =, <>, >, <, >=, <=

String Connection: ^

Two List connections: @

Data e and List es connection: e::es

Programming Language A study note (a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.