[back]

Grouping Integers and Strings

type int_or_string
  = Int of int
  | String of string

type int_list_or_string_list
  = Int_list of int list
  | String_list of string list

Implement the function

val convert : int_or_string list -> int_list_or_string_list list

so that convert l is a list of int_list_or_string_list values such that adjacent int values and string values in l are grouped together.

Examples

let test_in = [Int 2; Int 3; String "a"; String "b"; Int 4; String "c"]
let test_out = [Int_list [2;3]; String_list ["a";"b"]; Int_list [4]; String_list ["c"]]
let _ = assert (convert test_in = test_out)