File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,14 +64,30 @@ let list_product (xs: int list): int =
6464
6565(* * Näited. *)
6666
67+ module Foo =
68+ struct
69+ type t = bool
70+
71+ let x = 42
72+
73+ let f y = 2 * y
74+
75+ module Bar =
76+ struct
77+
78+ end
79+ end
80+
6781(* * Täisarvude hulkade moodul. *)
6882module IntSet = Set. Make (Int )
6983
7084(* * Teisendab täisarvude puu hulgaks.
7185 Vihje: IntSet.singleton.
7286 Vihje: IntSet.union. *)
7387let rec intset_of_tree (t : int tree ): IntSet.t =
74- failwith " TODO"
88+ match t with
89+ | Leaf x -> IntSet. singleton x
90+ | Branch (l , r ) -> IntSet. union (intset_of_tree l) (intset_of_tree r)
7591
7692
7793(* * Puu elementide mooduli tüüp/signatuur. *)
@@ -98,10 +114,14 @@ struct
98114
99115 (* * Teisendab puu hulgaks. *)
100116 let rec to_set (t : element tree ): Set.t =
101- failwith " TODO"
117+ match t with
118+ | Leaf x -> Set. singleton x
119+ | Branch (l , r ) -> Set. union (to_set l) (to_set r)
102120
103121 (* * Teisendab puu sõneks.
104122 Vihje: Element.show. *)
105123 let rec show (t : element tree ): string =
106- failwith " TODO"
124+ match t with
125+ | Leaf x -> Element. show x
126+ | Branch (l , r ) -> " (" ^ show l ^ " " ^ show r ^ " )"
107127end
You can’t perform that action at this time.
0 commit comments