module ChurchPrint open System let nil (c:'a->'b->'b) (n:'b) : 'b = n let cons (x:'a) (xs:('a->'b->'b)->'b->'b) : ('a->'b->'b)->'b->'b = fun c n -> c x (xs c n) let fold (xs:('a->'b->'b)->'b->'b) (c:'a->'b->'b) (n:'b) : 'b = xs c n let toList (xs:('a->'b->'b)->'b->'b) : 'a list = fold xs (fun x acc -> x :: acc) [] let printChurchTR (show:'a -> string) (xs:('a->'b->'b)->'b->'b) : unit = let rec loop l = match l with | [] -> () | h :: t -> printf "%s" (show h) if t <> [] then printf " " loop t xs |> toList |> loop printfn "" [] let main _ = let churchList = cons 1 (cons 2 (cons 3 nil)) printf "Числа: " printChurchTR string churchList let stringList = cons "Hello" (cons "World" (cons "F#" nil)) printf "Строки: " printChurchTR id stringList 0