type state = In | Out | Slash (* de completat cu alte stari *) let delta = function (* function: state -> char -> state *) | In -> (function | '\n' -> Out | _ -> In) | Out -> (function | '/' -> Slash | _ -> Out) | Slash -> (function | '/' -> In | _ -> Out) let rec fold_input state = (* ca fold_left, pe șirul caracterelor citite *) try let c = input_char stdin in (* încearcă să citească un caracter c *) fold_input (delta state c) (* aplică din nou pe starea următoare *) with _ -> state (* excepție la citire: returnează starea curentă *) (* starea acceptoare e Out -- textul se termina afara din comentariu *) let _ = print_endline (if fold_input Out = Out then "OK" else "ends in comment")