type _ fmt =
  | Txt: string * 'a fmt -> 'a fmt
  | Int: 'a fmt -> (int -> 'a) fmt
  | Done: unit fmt

let rec printf : type a. a fmt -> a =
  fun f ->
  match f with
  | Txt (s, f') -> print_string s; printf f'
  | Int f' ->
    fun x -> print_int x; printf f'
  | Done -> print_newline()

let () =
  printf (Txt ("abc", (Int Done))) 42
