Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

fill the foldt and the mirror(using foldt) by ocaml type 'a gt = Node of 'a*('a gt) list let mk_Leaf (n:'a) : 'a gt =

image text in transcribedimage text in transcribedimage text in transcribedfill the foldt and the mirror(using foldt) by ocamlimage text in transcribed

type 'a gt = Node of 'a*('a gt) list let mk_Leaf (n:'a) : 'a gt = Node(n, []) let t : int gt = Node (33, [Node (12,[]); Node (77, [Node (37, [Node (14, [1]); Node (48, []); Node (103, [])]) ]) let rec foldt : ('a -> 'b list -> 'b) -> 'a gt -> 'b = fun f (Node(d,ch)) -> failwith "implement" let sumt t = foldt (fun i rs -> i + List.fold_left (fun i j -> i+j) e rs) t let memt te = foldt (fun i rs -> i=e || List.exists (fun i -> i) rs) t let mirror' t failwith "implement" 8. foldt i t: that encodes the recursion scheme over general trees. Its type is foldt: (a -> b list -> b) -> 'a gt-> For example, here is how one may define sunt and went using folat: let sumt t- foldt (fun i rs -> Listfold_left (fun i j -> i+j) o ra) let nemt te- foldt (fun i rs -> i-. || List.exists (fun -> 1) rs) t For example, - int - 324 #memtt 12: :bool - true - bool - true #ment t35;: : bool - false 9. Implement mirror using foldt. It should behave just like Exercise 6. 6. mirror: that returns the mirror image of a general tree. Eg. #mirror ti - int gt Node (33. [Node (77, [Node (103, []); Node (48, []); Node (37, [Node (14, []))))) Node (12, []))) type 'a gt = Node of 'a*('a gt) list let mk_Leaf (n:'a) : 'a gt = Node(n, []) let t : int gt = Node (33, [Node (12,[]); Node (77, [Node (37, [Node (14, [1]); Node (48, []); Node (103, [])]) ]) let rec foldt : ('a -> 'b list -> 'b) -> 'a gt -> 'b = fun f (Node(d,ch)) -> failwith "implement" let sumt t = foldt (fun i rs -> i + List.fold_left (fun i j -> i+j) e rs) t let memt te = foldt (fun i rs -> i=e || List.exists (fun i -> i) rs) t let mirror' t failwith "implement" 8. foldt i t: that encodes the recursion scheme over general trees. Its type is foldt: (a -> b list -> b) -> 'a gt-> For example, here is how one may define sunt and went using folat: let sumt t- foldt (fun i rs -> Listfold_left (fun i j -> i+j) o ra) let nemt te- foldt (fun i rs -> i-. || List.exists (fun -> 1) rs) t For example, - int - 324 #memtt 12: :bool - true - bool - true #ment t35;: : bool - false 9. Implement mirror using foldt. It should behave just like Exercise 6. 6. mirror: that returns the mirror image of a general tree. Eg. #mirror ti - int gt Node (33. [Node (77, [Node (103, []); Node (48, []); Node (37, [Node (14, []))))) Node (12, [])))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students explore these related Databases questions