There is no built-in language construct that allows you to do this. Therefore, you must write the function yourself:
let tomorrow = function | MON -> TUE | TUE -> WED ...
Another possibility is to implement these functions:
val int_of_week: week -> int val week_of_int: int -> week
It happens that these functions are trivial to write with Obj.magic. They will allow you to implement tomorrow as:
let tomorrow w = week_of_int ((int_of_week w + 1) mod 7)
which is probably closer to what you had in mind.
But this solution is less secure:
- tomorrow's function assumes that int_of_week MON = 0, int_of_week TUE = 1, etc .;
- You need to document week_of_int behavior for integers that are not between 0 and 6;
- and, just as importantly, Obj.magic is not really part of the language.
source share