File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,14 @@ let list_product (xs: int list): int =
62
62
63
63
(* * Hulgad. *)
64
64
65
+ module Foo =
66
+ struct
67
+ type t = bool
68
+ let x = 42
69
+ let f y = 2 * y
70
+ (* let f = fun y -> 2 * y *)
71
+ end
72
+
65
73
(* * Näited. *)
66
74
67
75
(* * Täisarvude hulkade moodul. *)
@@ -71,7 +79,10 @@ module IntSet = Set.Make (Int)
71
79
Vihje: IntSet.singleton.
72
80
Vihje: IntSet.union. *)
73
81
let rec intset_of_tree (t : int tree ): IntSet.t =
74
- failwith " TODO"
82
+ (* IntSet.of_list (list_of_tree t) *)
83
+ match t with
84
+ | Leaf x -> IntSet. singleton x
85
+ | Branch (l , r ) -> IntSet. union (intset_of_tree l) (intset_of_tree r)
75
86
76
87
77
88
(* * Puu elementide mooduli tüüp/signatuur. *)
@@ -98,10 +109,14 @@ struct
98
109
99
110
(* * Teisendab puu hulgaks. *)
100
111
let rec to_set (t : element tree ): Set.t =
101
- failwith " TODO"
112
+ match t with
113
+ | Leaf x -> Set. singleton x
114
+ | Branch (l , r ) -> Set. union (to_set l) (to_set r)
102
115
103
116
(* * Teisendab puu sõneks.
104
117
Vihje: Element.show. *)
105
118
let rec show (t : element tree ): string =
106
- failwith " TODO"
119
+ match t with
120
+ | Leaf x -> Element. show x
121
+ | Branch (l , r ) -> " (" ^ show l ^ " " ^ show r ^ " )"
107
122
end
You can’t perform that action at this time.
0 commit comments