parent
d1ae3c3da0
commit
119b178360
@ -0,0 +1,39 @@
|
||||
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 ""
|
||||
|
||||
[<EntryPoint>]
|
||||
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
|
@ -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>
|
@ -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…
Reference in new issue