From d1ae3c3da0d313d52def85a4a9f2216ae3a39b50 Mon Sep 17 00:00:00 2001 From: Artem-Darius Weber Date: Thu, 17 Apr 2025 20:54:29 +0300 Subject: [PATCH] lab 6 task 1 --- lab6/Makefile | 23 +++++++++++++++++++++ lab6/task1/Program.fs | 45 +++++++++++++++++++++++++++++++++++++++++ lab6/task1/task1.fsproj | 12 +++++++++++ 3 files changed, 80 insertions(+) create mode 100644 lab6/Makefile create mode 100644 lab6/task1/Program.fs create mode 100644 lab6/task1/task1.fsproj diff --git a/lab6/Makefile b/lab6/Makefile new file mode 100644 index 0000000..6d2309e --- /dev/null +++ b/lab6/Makefile @@ -0,0 +1,23 @@ +.PHONY: run build clean task1 build-task1 clean-task1 + +# task1 +run: + cd task1 && dotnet run --project task1.fsproj + +build: + cd task1 && dotnet build + +clean: + cd task1 && dotnet clean + +all: build run + +# task1 (alternative targets) +task1: + cd task1 && dotnet run --project task1.fsproj + +build-task1: + cd task1 && dotnet build + +clean-task1: + cd task1 && dotnet clean diff --git a/lab6/task1/Program.fs b/lab6/task1/Program.fs new file mode 100644 index 0000000..baf5744 --- /dev/null +++ b/lab6/task1/Program.fs @@ -0,0 +1,45 @@ +module Church + +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 append (xs:('a->'b->'b)->'b->'b) (ys:('a->'b->'b)->'b->'b) : ('a->'b->'b)->'b->'b = + fun c n -> xs c (ys c n) + +let singleton (x:'a) : (('a->'b->'b)->'b->'b) = + cons x nil + +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 = + xs (fun x acc -> x :: acc) [] + +let ofList (ls:'a list) : (('a->'b->'b)->'b->'b) = + List.foldBack (fun x acc -> cons x acc) ls nil + +let readNChurch (parse:string->'a) (n:int) : (('a->'b->'b)->'b->'b) = + let rec loop i acc = + if i = 0 then acc nil + else + let x = parse (Console.ReadLine()) + loop (i - 1) (fun tail -> acc (cons x tail)) + loop n id + +let readNInt (n:int) = + readNChurch int n + +let readNString (n:int) = + readNChurch id n + +[] +let main _ = + let n = Console.ReadLine() |> int + let clist = readNInt n + let lst = toList clist + lst |> List.iter (printfn "%d") + 0 \ No newline at end of file diff --git a/lab6/task1/task1.fsproj b/lab6/task1/task1.fsproj new file mode 100644 index 0000000..878876c --- /dev/null +++ b/lab6/task1/task1.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net7.0 + + + + + + + \ No newline at end of file