// // Title: Concepts of Programming Languages // Number: CAS CS 320 // Semester: Fall 2012 // Class Time: TR 12:30-2:00 // Instructor: Hongwei Xi (hwxiATcsDOTbuDOTedu) // Teaching Fellow: Alex Ren (arenATcsDOTbuDOTedu) // (* // // Assignment #4 // Due Friday, February 15, 2013 at 11:59pm // *) (* ****** ****** *) // // Problem 1: 50 points // (* ****** ****** *) #include "BUCASCS320-6.hats" (* ****** ****** *) staload "GameOf24.sats" (* ****** ****** *) assume cardset_type = list0 (card) (* ****** ****** *) implement cardset_make_nil () = list0_nil () (* ****** ****** *) implement cardset_get_at (xs, i) = list0_nth_exn (xs, i) (* ****** ****** *) implement cardset_size (xs) = list0_length (xs) (* ****** ****** *) implement cardset_add_card (xs, x) = list0_cons (x, xs) (* ****** ****** *) exception IllgalArgument of () (* fun cardset_take2 (xs: cardset, i: int, j: int): (cardset, card, card) *) implement cardset_take2 (xs, i, j) = let // fun aux ( xs: cardset, i: int, j: int ) : (cardset, card, card) = let in // case+ xs of | list0_cons (x, xs) => if i > 0 then let val (ys, yi, yj) = aux (xs, i-1, j-1) in (list0_cons (x, ys), yi, yj) end else let // i = 0 val (ys, yj) = aux2 (xs, j-1) in (ys, x, yj) end | list0_nil () => \$raise IllgalArgument () // end // end of [aux] // and aux2 ( xs: cardset, j: int ) : (cardset, card) = let in // case+ xs of | list0_cons (x, xs) => if j > 0 then let val (ys, yj) = aux2 (xs, j-1) in (list0_cons (x, ys), yj) end else // j = 0 (xs, x) // end of [if] | list0_nil () => \$raise IllgalArgument () // end // end of [aux2] // in aux (xs, i, j) end // end of [cardset_take2] (* ****** ****** *) (* end of [GameOf24_cardset.dats] *)