Skip to content

Commit

Permalink
Changed sets to proper representation (test * (student * outcome) lis…
Browse files Browse the repository at this point in the history
…t), added set equality
  • Loading branch information
jwelch01 committed Nov 3, 2011
1 parent f14751d commit b0e5826
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
25 changes: 6 additions & 19 deletions partition-fest/structures/outcome.sml
Expand Up @@ -10,27 +10,14 @@ structure Outcome :> OUTCOME = struct
} }




fun compare (PASSED, PASSED) = EQUAL
| compare (PASSED, _ ) = GREATER
| compare (NOTPASSED _, PASSED) = LESS
| compare (NOTPASSED _, _ ) = EQUAL


fun compareOutcome (PASSED, PASSED) = EQUAL fun eq (o1, o2) =
| compareOutcome (PASSED, _ ) = GREATER (case compare (o1, o2)
| compareOutcome (NOTPASSED _, PASSED) = LESS
| compareOutcome (NOTPASSED _, _ ) = EQUAL

fun eqOutcome (o1, o2) =
(case compareOutcome (o1, o2)
of EQUAL => true of EQUAL => true
| _ => false) | _ => false)


fun sameTest ((id1, num1), (id2, num2)) =
id1= id2 andalso num1 = num2

exception DifferentTests
fun compare ((id1, num1, sid1, out1), (id2, num2, sid2, out2)) =
if sameTest ((id1, num1), (id2, num2))
then compareOutcome (out1, out2)
else raise DifferentTests

fun eq ((id1, num1, sid1, out1), (id2, num2, sid2, out2)) =
sameTest ((id1, num1), (id2, num2)) andalso eqOutcome (out1, out2)

end end
9 changes: 2 additions & 7 deletions partition-fest/structures/outcomesig.sml
Expand Up @@ -8,13 +8,8 @@ signature OUTCOME = sig
, outcome : outcome , outcome : outcome
} }


val compareOutcome : outcome * outcome -> order val compare : outcome * outcome -> order
val eqOutcome : outcome * outcome -> bool


val sameTest : (string * int) * (string * int) -> bool val eq : outcome * outcome -> bool


exception DifferentTests
val compare : t * t -> order

val eq : t * t -> bool (* does not compare solnid *)
end end
26 changes: 22 additions & 4 deletions partition-fest/structures/set.sml
@@ -1,17 +1,35 @@
functor Set (Outcome : OUTCOME) : SET = struct functor Set (Outcome : OUTCOME) : SET = struct
type elem = Outcome.t type elem = (string * int * (string * Outcome.outcome) list)
type set = elem list type set = elem list


exception NotFound exception NotFound
exception NotFinished exception NotFinished




fun insertion_sort _ [] = []
| insertion_sort cmp (x::xs) = insert cmp x (insertion_sort cmp xs)
and insert _ x [] = [x]
| insert cmp x (l as y::ys) =
case cmp (x, y) of GREATER => y :: insert cmp x ys
| _ => x :: l
fun cmpResultName ((x, _), (y, _)) = String.compare (x, y)

fun sort l = insertion_sort cmpResultName l

fun eqResult ((id, num, ol), (id2, num2, ol2)) =
id = id2 andalso num = num2 andalso
(ListPair.foldrEq (fn ((_,out1), (_,out2), flag) =>
Outcome.eq (out1, out2) andalso flag) true (ol, ol2)
handle UnequalLengths => false)

val empty = [] val empty = []
fun add (x, s) = x::s fun add (x, s) = x::s
fun member (x, s) = List.exists (fn y => Outcome.eq (y,x)) s
fun member ((id, num, ol), s) = List.exists
(fn (id2, num2, ol2) => eqResult ((id, num, ol), (id2, num2, ol2))) s

fun representative [] = NONE fun representative [] = NONE
| representative (x::_) = SOME x | representative (x::_) = SOME x

fun rep x = case representative x of SOME y => y fun rep x = case representative x of SOME y => y
| NONE => raise NotFound | NONE => raise NotFound


Expand All @@ -33,7 +51,7 @@ functor Set (Outcome : OUTCOME) : SET = struct
end end


fun /<=/ (_,_) = raise NotFinished fun /<=/ (_,_) = raise NotFinished
fun /==/ (_,_) = raise NotFinished fun /==/ (set1, set2) = eqResult (rep set1, rep set2)


fun /*/ (_,_) = raise NotFinished fun /*/ (_,_) = raise NotFinished
fun /+/ (_,_) = raise NotFinished fun /+/ (_,_) = raise NotFinished
Expand Down

0 comments on commit b0e5826

Please sign in to comment.