Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed sets to proper representation (test * (student * outcome) lis…

…t), added set equality
  • Loading branch information...
commit b0e5826ac715ef57155943039beadfd9446cfca2 1 parent f14751d
@jwelch01 authored
View
25 partition-fest/structures/outcome.sml
@@ -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
- | compareOutcome (PASSED, _ ) = GREATER
- | compareOutcome (NOTPASSED _, PASSED) = LESS
- | compareOutcome (NOTPASSED _, _ ) = EQUAL
-
-fun eqOutcome (o1, o2) =
- (case compareOutcome (o1, o2)
+fun eq (o1, o2) =
+ (case compare (o1, o2)
of EQUAL => true
| _ => 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
View
9 partition-fest/structures/outcomesig.sml
@@ -8,13 +8,8 @@ signature OUTCOME = sig
, outcome : outcome
}
- val compareOutcome : outcome * outcome -> order
- val eqOutcome : outcome * outcome -> bool
+ val compare : outcome * outcome -> order
- 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
View
26 partition-fest/structures/set.sml
@@ -1,17 +1,35 @@
functor Set (Outcome : OUTCOME) : SET = struct
- type elem = Outcome.t
+ type elem = (string * int * (string * Outcome.outcome) list)
type set = elem list
exception NotFound
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 = []
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
| representative (x::_) = SOME x
-
fun rep x = case representative x of SOME y => y
| NONE => raise NotFound
@@ -33,7 +51,7 @@ functor Set (Outcome : OUTCOME) : SET = struct
end
fun /<=/ (_,_) = raise NotFinished
- fun /==/ (_,_) = raise NotFinished
+ fun /==/ (set1, set2) = eqResult (rep set1, rep set2)
fun /*/ (_,_) = raise NotFinished
fun /+/ (_,_) = raise NotFinished
Please sign in to comment.
Something went wrong with that request. Please try again.