Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/ConstraintGrader.fun
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
functor ConstraintGrader (
(* Constraint Grader should return 1.0 if no constraint was violated *)
structure Constraint : GRADER
structure Correctness : GRADER
val description : string
(* deduction is the fraction of the total points that will be deducted, this
* should be Rational.one, as violating constraints deducts all points
*)
val deduction : Rational.t
val deductionMessage : string
) :> GRADER =
struct
structure Rubric =
struct
val description = description

type t = Correctness.Rubric.t * Constraint.Rubric.t

fun toString (correctness, constraint) =
let
val passes = Rational.eq (Rational.one, Constraint.Rubric.score constraint)
val deductionPercent =
showPercentsUnweighted (if passes then Rational.zero else Rational.~ deduction, Rational.zero)
val deductionMessage = if passes then "" else deductionMessage
in
String.concat [
Correctness.Rubric.toString correctness,
deductionPercent ^ " " ^ Constraint.Rubric.description ^ "\n",
FormatUtil.indent (Constraint.Rubric.toString constraint),
FormatUtil.indent deductionMessage
]
end

fun score (correctness, constraint) =
let
val correctnessScore = Correctness.Rubric.score correctness
val deduction =
if Rational.eq (Rational.one, Constraint.Rubric.score constraint)
then Rational.zero
else deduction
in
case (Rational.compare (correctnessScore, deduction)) of
LESS => Rational.zero
| _ => Rational.- (correctnessScore, deduction)
end
end

fun process () = (Correctness.process (), Constraint.process ())
end
9 changes: 6 additions & 3 deletions src/FormatUtil.sml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ structure FormatUtil =
local
val padded = StringCvt.padLeft #" " 4 o Rational.percent
in
val showPercents = fn (score,weight) =>
"(" ^ padded (Rational.* (weight,score)) ^
"/" ^ padded weight ^ "):"
val showPercentsUnweighted = fn (numerator, denominator) =>
"(" ^ padded numerator ^
"/" ^ padded denominator ^ "):"
end

val showPercents = fn (score,weight) =>
showPercentsUnweighted (Rational.* (weight, score), weight)

val indentWith = fn s0 =>
let
val spaces = String.implode (List.tabulate (String.size s0, Fn.const #" "))
Expand Down
4 changes: 4 additions & 0 deletions src/sources.cm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Library
functor EquivGraderBucketList
functor EquivGraderList

functor ConstraintGrader

functor Preamble

structure FormatUtil
Expand Down Expand Up @@ -49,6 +51,8 @@ is
EquivGraderBucket.fun
EquivGrader.fun

ConstraintGrader.fun

Preamble.fun

FormatUtil.sml