lecture-3

lecture-3 - CSE 130 : Winter 2010 Recap: a quicksort...

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

View Full Document Right Arrow Icon
1 CSE 130 : Winter 2010 Programming Languages UC San Diego Expressions and Types Recap: a “quicksort” function let rec sort l = match l with [] -> [] | (h::t) -> let (l,r) = partition ((<) h) t in (sort l)@(h::(sort r)) ;; What’s the difference? void sort(int arr[], int beg, int end){ if (end > beg + 1){ int piv = arr[beg]; int l = beg + 1; int r = end; while (l != r-1){ if(arr[l] <= piv) l++; else swap(&arr[l], &arr[r--]); } l=r+1; {l++; r--;} swap(&arr[l++], &arr[r--]); else r=l-1; swap(&arr[r--], &arr[beg]); sort(arr, beg, r); sort(arr, l, end); } } let rec sort l = match l with [] -> [] |(h::t) -> let(l,r)= partition ((<=) h) t in (sort l)@h::(sort r) Style exercise Begin at the beginning … 1. Programmer enters expression 2. ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression meaningful type for the expr 3. ML evaluates expression to compute value Of the same “type” found in step 2 Expressions (Syntax) Values (Semantics) Types Compile-time “Static” Exec-time “Dynamic” Base Types
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Base Type: int Expressions built from sub-expressions Types computed from types of sub-expressions Values computed from values of sub-expressions 2+3; 5 7-4; 3 (2+3)*(7-4); 15 2; 2 i : int i i i e 1 : int e 2 : int e 1 +e 2 : int e1 v1 e2 v2 e1+e2 v1+v2 e1 + e2 e1 - e2 e1 * e2 e 1 : int e 2 : int e 1 -e 2 : int e1 v1 e2 v2 e1-e2 v1-v2 e 1 : int e 2 : int e 1 * e 2 : int e1 v1 e2 v2 e1*e2 v1*v2 Base Type: float Expressions built from sub-expressions
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/08/2011 for the course CSE cse130 taught by Professor Cs during the Fall '10 term at UCSD.

Page1 / 4

lecture-3 - CSE 130 : Winter 2010 Recap: a quicksort...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online