Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- type Field =
- | SimpleField of SimpleField
- | Type of Type
- and Type =
- { Name: string
- Fields: Field list }
- and SimpleField =
- { Name: string
- Type: string }
- type A = {
- AS: A list
- }
- let flattern a =
- let rec loop a acc =
- match a with
- | { Fields = [] } -> acc
- | { Fields = list } ->
- let types =
- list
- |> List.map(function Type x -> Some { Name = x.Name; Fields = x.Fields } | _ -> None)
- |> List.choose id
- match types with
- | [] -> acc
- | x::xs -> loop ({ Name = ""; Fields = xs |> List.map (Type) }) (loop x (x::acc))
- loop a [a]
- let flattern2 aObj =
- let rec loop aObj cont =
- match aObj with
- | { AS = [] } -> cont []
- | { AS = x::xs } ->
- loop { AS = xs } (fun acc -> loop x (fun q -> cont ([x] @ q @ acc)))
- aObj :: loop aObj id
- let sum1 n =
- let rec f n cont =
- match n with
- | 1 -> cont 1
- | n -> f (n-1) (fun n1->cont(n+n1))
- f n id
- [<EntryPoint>]
- let main argv =
- let test = sum1 3
- let types =
- { Name = "Root"
- Fields = [
- Type { Name = "PersonalData"; Fields = [
- SimpleField { Name = "email"; Type = "string" }
- Type { Name = "Address"; Fields = [
- SimpleField { Name = "id"; Type = "string" }
- ] }
- ] }
- SimpleField { Name = "name"; Type = "string" }
- SimpleField { Name = "lastName"; Type = "string" }
- Type { Name = "Address"; Fields = [
- SimpleField { Name = "address1"; Type = "string" }
- SimpleField { Name = "address2"; Type = "string" }
- SimpleField { Name = "zipcode"; Type = "int" }
- ] }
- ] }
- let a = {
- AS = [
- { AS = [
- { AS = [] }
- ] }
- { AS = [{ AS = [] }] }
- ]
- }
- let a2 = {
- AS = [
- ]
- }
- let test1 = flattern types
- Console.ReadKey() |> ignore
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement