Modify your function to accept a string converter and use it in your implementation. Then, when you call it, go to the appropriate converter and range. Sort of:
let string_of_range str_conv = function
| Full -> "Full"
| Range(a, b) -> "Range (" ^ (str_conv a) ^ ", " ^ (str_conv b) ^ ")"
It will be of type: string_of_range : ('a -> string) -> 'a range -> string
Call example:
string_of_range string_of_int (Range (1, 2))
Arranged this way, you can easily create more specialized converters.
let string_of_int_range = string_of_range string_of_int
It will be of type: string_of_int_range : int range -> string
source
share