# Ln009 - ML Tuples Lists ML groups information using tuples You can think of tuples as records of values that describe a particular object Examples

This preview shows pages 1–4. Sign up to view the full content.

ML groups information using tuples You can think of tuples as records of values that describe a particular object Examples: - val joe = (32,185,”married”,”pilot”); val joe = (32,185,”married”,”pilot”) : int * int * string * string age weight tuple type - val circle = ((2.5,3.6),5.0); val circle = ((2.5,3.6),5.0) : (real * real) * real xy-coord. radius

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
We can extract specific values from tuples using projections e.g., to retrieve the i th value from tuple X: #i X - val joe = (32,185,”married”,”pilot”); - val age = #1 joe; - val profession = #4 joe; -val circle = ((2.5,3.6),5.0); - val radius = #2 circle; - val x = #1 (#1 circle); - val y = ?
ML supports another kind of tuple called a list A list is a tuple where all elements are of the same type - val oddlist = [ 1, 3, 5, 7, 9 ]; val oddlist = [ 1, 3, 5, 7, 9 ] : int list different from tuples! - val nested = [(1,2),(3,4)];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.

### Page1 / 10

Ln009 - ML Tuples Lists ML groups information using tuples You can think of tuples as records of values that describe a particular object Examples

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online