Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type grade = Pass | No_pass
- module type STUDENT = sig
- type student
- val make : string -> student
- val get_tests : student -> int list
- end
- module Student : STUDENT = struct
- type student = {
- name : string;
- tests : int list;
- course_grade : grade option;
- }
- let make name = {
- name = name;
- tests = [];
- course_grade = None
- }
- let get_tests s = s.tests
- let get_test_score s i = List.nth s.tests i
- end
- module type GRADSTUDENT = sig
- include module type of Student
- val compute_course_grade : student -> int
- end
- module GraduateStudent : GRADSTUDENT = struct
- include Student
- let compute_course_grade s =
- let tests = s.tests in (* <-- THIS WON'T COMPILE *)
- let total = List.fold_left (+) 0 tests in
- let grade = match total / List.length tests with
- | q when q > 80 -> Pass
- | _ -> No_pass
- in
- 10
- end
Advertisement
Add Comment
Please, Sign In to add comment