Guest User

Untitled

a guest
Jun 8th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.85 KB | None | 0 0
  1. type grade = Pass | No_pass
  2.  
  3. module type STUDENT = sig
  4.     type student
  5.     val make : string -> student
  6.     val get_tests : student -> int list
  7. end
  8.  
  9. module Student : STUDENT = struct
  10.     type student = {
  11.         name : string;
  12.         tests : int list;
  13.         course_grade : grade option;
  14.     }
  15.  
  16.     let make name = {
  17.         name = name;
  18.         tests = [];
  19.         course_grade = None
  20.     }
  21.  
  22.     let get_tests s = s.tests
  23.  
  24.     let get_test_score s i = List.nth s.tests i
  25.  
  26. end
  27.  
  28. module type GRADSTUDENT = sig
  29.     include module type of Student
  30.     val compute_course_grade : student -> int
  31. end
  32.  
  33. module GraduateStudent : GRADSTUDENT = struct
  34.     include Student
  35.     let compute_course_grade s =
  36.         let tests = s.tests in  (* <-- THIS WON'T COMPILE *)
  37.         let total = List.fold_left (+) 0 tests in
  38.         let grade = match total / List.length tests with
  39.             | q when q > 80 -> Pass
  40.             | _ -> No_pass
  41.         in
  42.         10
  43. end
Advertisement
Add Comment
Please, Sign In to add comment