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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 = ?
Background image of page 2
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)];
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
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 Right Arrow Icon
Ask a homework question - tutors are online