Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 905 Bytes

README.md

File metadata and controls

27 lines (23 loc) · 905 Bytes

Student grades

Consider the following type to represent student grades:

type grade = Val of int | CumLaude;;

Write functions with the following types:

is_valid : grade -> bool

which evaluates to true iff the grade is included between 18 and 30, or it is CumLaude.

int_of_grade : grade -> int

which transforms a valid grade into an integer (where CumLaude counts for 32), and fails if the grade is not valid.

avg : grade list -> float

which computes the average of a list of valid grades (it fails if some grade in the list is not valid).

Finally, write a function with type:

avg_norec : grade list -> float

that takes as input a list of grades (not necessarily valid) and outputs the average of all the valid grades in the list. This function must use list combinators and function pipelining, and must not use recursion.