lab 6 task 1

main
Artem-Darius Weber 6 months ago
parent 0ff00d9d25
commit d1ae3c3da0

@ -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

@ -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
[<EntryPoint>]
let main _ =
let n = Console.ReadLine() |> int
let clist = readNInt n
let lst = toList clist
lst |> List.iter (printfn "%d")
0

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
</Project>
Loading…
Cancel
Save