File tree 2 files changed +17
-13
lines changed
2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ let () = Debug.log (String.of-int (Ref.get r)) in % 1
53
53
54
54
let () = Debug.log `==== String ====` in
55
55
let () = Debug.log (String.concat [`a`; `b`; `c`;]) in
56
- let () = Debug.log (String.with- concat `;` [`a`; `b`; `c`;]) in
56
+ let () = Debug.log (String.concat ?:( `;`) [`a`; `b`; `c`;]) in
57
57
let () = Debug.log (String.of-bool (String.is-empty ` `)) in % true
58
58
let _ = String.split-by (Char.make `;`) `spam;ham;eggs;` |> List.map Debug.log in
59
59
let _ = String.to-list `abc` |> List.map (fun c -> (c |> String.of-char |> Debug.log)) in
@@ -360,7 +360,7 @@ let () = Debug.log `==== TreeSet ====` in
360
360
% REMARK:
361
361
% This test relies on the fact that the order of elements of a result from TreeSet.to-list is
362
362
% level-order (BFS). If the implementation is changed, the following tests have to be updated.
363
- let p s = s |> TreeSet.to-list |> List.map String.of-int |> List.intersperse `,` |> String.concat |> Debug.log in
363
+ let p s = s |> TreeSet.to-list |> List.map String.of-int |> List.intersperse `,` |> (fun l -> String.concat l) |> Debug.log in
364
364
let s = TreeSet.empty in
365
365
let () = p s in
366
366
let s = TreeSet.of-list Int.ord [3;2;3;1] in
Original file line number Diff line number Diff line change @@ -26,9 +26,7 @@ module String : sig
26
26
val of-char : Char.t -> string
27
27
val of-length : length -> string
28
28
val append : string -> string -> string
29
- val with-concat : string -> string list -> string
30
- val concat : string list -> string
31
- val cat : string -> string -> string
29
+ val concat : string ?-> string list -> string
32
30
val is-empty : string -> bool
33
31
val starts-with : string -> string -> bool
34
32
val ends-with : string -> string -> bool
@@ -67,15 +65,21 @@ end = struct
67
65
let append s1 s2 = s1 ^ s2
68
66
69
67
70
- let-rec with-concat s xs =
71
- match xs with
72
- | [] -> empty
73
- | [x] -> x
74
- | x :: xs -> x ^ s ^ with-concat s xs
75
68
76
- let concat xs = with-concat empty xs
69
+ let concat ?:s xs =
70
+ let s =
71
+ match s with
72
+ | None -> empty
73
+ | Some(s) -> s
74
+ in
75
+ let-rec sub xs =
76
+ match xs with
77
+ | [] -> empty
78
+ | [x] -> x
79
+ | x :: xs -> x ^ s ^ sub xs
80
+ in
81
+ sub xs
77
82
78
- let cat = (^)
79
83
80
84
let is-empty s =
81
85
equal s empty
@@ -96,7 +100,7 @@ end = struct
96
100
|> List.map Char.of-codepoint
97
101
98
102
let of-list chars =
99
- chars |> List.map Char.to-string |> concat
103
+ chars |> List.map Char.to-string |> (fun slst -> concat slst)
100
104
101
105
let pow n s =
102
106
let-rec go i acc = if i == n then acc else go (i + 1) (acc ^ s) in
You can’t perform that action at this time.
0 commit comments