1 / 5

CS603 Programming Language Organization

CS603 Programming Language Organization. Lecture 23 Spring 2004 Department of Computer Science University of Alabama. Example: merge sort.

azia
Download Presentation

CS603 Programming Language Organization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS603 Programming Language Organization • Lecture 23 • Spring 2004 • Department of Computer Science • University of Alabama

  2. Example: merge sort • fun msort L =let val halves = split Lin merge (msort (hd halves)) (msort (hdtl halves))endfun split [] = [[], []] | split [a] = [[a], []] | split (a::b::t) = let val splittltl = split t in [a::(hd splittltl), b::(hdtl splittltl)] end; Pair up: Write merge

  3. merge • fun merge ([], ys) = ys merge (xs, []) = xs merge (x::xs, y::ys) = if x <= y then x::merge(xs, y::ys) else y::merge(x::xs, ys);

  4. Algebraic Data-types • datatype 'a tree = Empty | Node of 'a tree * 'a * 'a treefun height Empty = 0 | height (Node (lft, _, rht)) = 1 + max (height lft, height rht)

  5. Resources • “Programming in Standard ML” • http://www-2.cs.cmu.edu/~rwh/smlbook/offline.pdf • Source code from above book • http://www-2.cs.cmu.edu/~rwh/smlbook/examples/ • Moscow ML • http://www.dina.dk/~setsoft/mosml.html

More Related