# lec4 - (* CSE 341, Spring 2008 *) ( (* Lecture 4: records,...

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

(* CSE 341, Spring 2008 *) (* Lecture 4: records, datatypes *) ( (* records *) ( fun make_my_triple (x,y,z) = {larry=x, curly=y, moe=z} fun is_larry_positive (trip : {larry:int,curly:int,moe:int} ) = #larry trip > 0 (*records are just tuples with user-defined field names*) ( (*or tuples are just records with names 1, 2, 3, . ..*) ( (*but the syntax for construction varies: "by position" vs "by name"*) val a_pair = (3,4) val a_record = {second=4, first=3} v (* actually, tuples _are_ just records with names 1, 2, 3, . .. and special "by position" syntax -- our first "syntactic sugar" example *) val another_pair = {2=5, 1=6} val sum = (#1 a_pair + #1 another_pair, #2 a_pair + #2 another_pair) v (* datatypes *) ( datatype mytype = TwoInts of int * int | Str of string | Pizza val a = Str "hi" val b = Str val c = Pizza v (* Do _not_ redo datatype bindings (e.g., via use "lec4.sml") datatype mytype = TwoInts of int * int | Str of string | Pizza *) d val d = a v fun f1 x = case x of Pizza => 3 | Str s => 8

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/12/2009 for the course CSE 341 taught by Professor Staff during the Spring '08 term at University of Washington.

### Page1 / 2

lec4 - (* CSE 341, Spring 2008 *) ( (* Lecture 4: records,...

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

View Full Document
Ask a homework question - tutors are online