Skip to content

Commit d592e2f

Browse files
committed
update to use labelled interface
1 parent 96fe300 commit d592e2f

File tree

15 files changed

+183
-183
lines changed

15 files changed

+183
-183
lines changed

examples/cbor/cbor_explorer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ let ui_of_cbor (c:C.t) =
5757
in
5858
W.unfoldable summary (fun () -> traverse ~fold:false y)
5959
in
60-
let w = Lwd.map2 Ui.Ui.join_y
60+
let w = Lwd.map2 ~f:Ui.Ui.join_y
6161
w_q (Nottui_widgets.scroll_area @@ traverse ~fold:true c)
6262
in
6363
quit, w

examples/minesweeper/main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let event_input event =
2121
| Some target -> Some (Js.to_string target##.value)
2222

2323
let int_input name value ~set_value =
24-
let value = Lwd.map string_of_int value in
24+
let value = Lwd.map ~f:string_of_int value in
2525
children [
2626
Html.txt (Lwd.pure name);
2727
Html.input ~a:[

examples/minesweeper/minesweeper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ let cell_image_src cell =
168168

169169
let cell_image cell ~on_click =
170170
Html.img
171-
~src:(Lwd.map cell_image_src cell)
171+
~src:(Lwd.map ~f:cell_image_src cell)
172172
~alt:(Lwd.pure "Hello")
173173
~a:[Html.a_onclick (Lwdom.attr (fun _ -> on_click ()))]
174174
()

examples/minimal.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ let degrees = Lwd.var 0.0
3838
let farenheit = Lwd.var (nan, ("", 0))
3939

4040
let farenheit_text =
41-
Lwd.map2' (Lwd.get degrees) (Lwd.get farenheit)
42-
(fun d (d', f) ->
43-
if d = d' then f else (string_of_float (c_to_f d), 0))
41+
Lwd.map2 (Lwd.get degrees) (Lwd.get farenheit)
42+
~f:(fun d (d', f) ->
43+
if d = d' then f else (string_of_float (c_to_f d), 0))
4444

4545
let farenheit_edit =
4646
Nottui_widgets.edit_field
@@ -57,8 +57,8 @@ let farenheit_edit =
5757
let celsius = Lwd.var (nan, ("", 0))
5858

5959
let celsius_text =
60-
Lwd.map2' (Lwd.get degrees) (Lwd.get celsius)
61-
(fun d (d', f) -> if d = d' then f else (string_of_float d, 0))
60+
Lwd.map2 (Lwd.get degrees) (Lwd.get celsius)
61+
~f:(fun d (d', f) -> if d = d' then f else (string_of_float d, 0))
6262

6363
let celsius_edit =
6464
Nottui_widgets.edit_field

examples/pretty.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ let fruit =
2626
let fruits = ["Apple"; "Orange"; "Strawberry"] in
2727
let choice = Lwd.var (List.hd fruits) in
2828
Lwd.join (
29-
Lwd.map' (Lwd.get choice) (fun current ->
30-
selector current (Lwd.set choice) fruits
31-
)
29+
Lwd.map (Lwd.get choice)
30+
~f:(fun current -> selector current (Lwd.set choice) fruits)
3231
)
3332

3433
let doc = Lwd_table.make ()
@@ -48,7 +47,7 @@ let () =
4847
P.hardline; P.ui (Ui.space 0 1); P.hardline;
4948
];
5049
Lwd_table.append' doc
51-
(Lwd.map' fruit (fun fruit ->
50+
(Lwd.map fruit ~f:(fun fruit ->
5251
P.group (spring ^^ string "I" ^^ spring ^/^
5352
P.group (string "like" ^^ spring ^/^
5453
P.ui fruit ^^ spring ^/^
@@ -58,17 +57,16 @@ let () =
5857

5958
let varying_width f =
6059
let width = Lwd.var 0 in
61-
Lwd.map'
62-
(f (Lwd.get width))
63-
(fun ui ->
64-
Ui.size_sensor
65-
(fun ~w ~h:_ -> if Lwd.peek width <> w then Lwd.set width w)
66-
(Ui.resize ~sw:1 ~sh:1 ~w:0 ui))
60+
Lwd.map (f (Lwd.get width)) ~f:(fun ui ->
61+
Ui.size_sensor
62+
(fun ~w ~h:_ -> if Lwd.peek width <> w then Lwd.set width w)
63+
(Ui.resize ~sw:1 ~sh:1 ~w:0 ui)
64+
)
6765

6866
let doc =
6967
Lwd.join (Lwd_table.reduce (Lwd_utils.lift_monoid (P.empty, P.(^^))) doc)
7068

71-
let contents width = Lwd.map2' width doc P.pretty
69+
let contents width = Lwd.map2 ~f:P.pretty width doc
7270

7371
let () =
7472
Lwd.set base (

examples/reranger.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ let rec dir ?(initial_path = []) ?after_width:(wref = ref 0) path =
4747
in
4848
let t = Lwd_utils.pack Ui.pack_y [ Lwd.return header; body ] in
4949
let t =
50-
if constrain then Lwd.map (Ui.resize ~w:12) t
51-
else Lwd.map (remember_width ~wref) t
50+
if constrain then Lwd.map ~f:(Ui.resize ~w:12) t
51+
else Lwd.map ~f:(remember_width ~wref) t
5252
in
5353
column $= Lwd_utils.pack Ui.pack_x [ t; Lwd.join (Lwd.get after) ]
5454
in
@@ -61,7 +61,7 @@ let rec dir ?(initial_path = []) ?after_width:(wref = ref 0) path =
6161
with exn ->
6262
Lwd.return (string ~attr:Notty.(A.bg A.red) (Printexc.to_string exn))
6363
in
64-
after $= Lwd.map (Ui.join_x (string " ")) t
64+
after $= Lwd.map ~f:(Ui.join_x (string " ")) t
6565
in
6666
let highlighted_cell = ref None in
6767
let rec render_directory ?(highlight = false) cell name =
@@ -137,6 +137,6 @@ let () =
137137
dir ~initial_path "/"
138138
]
139139
in
140-
Lwd.set body (Lwd.map (Ui.resize ~pad:gravity_pad ~crop:gravity_crop) ui);
140+
Lwd.set body (Lwd.map ~f:(Ui.resize ~pad:gravity_pad ~crop:gravity_crop) ui);
141141
Ui_loop.run (Nottui_widgets.window_manager_view wm)
142142

lib/lwd/lwd.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,18 @@ let dummy = Pure (Any.any ())
8282
let operator desc =
8383
Operator { value = Eval_none; trace = T0; desc; trace_idx = I0 }
8484

85-
let map f x = inj (
85+
let map x ~f = inj (
8686
match prj x with
8787
| Pure vx -> Pure (f vx)
8888
| x -> operator (Map (x, f))
8989
)
9090

91-
let map2 f x y = inj (
91+
let map2 x y ~f = inj (
9292
match prj x, prj y with
9393
| Pure vx, Pure vy -> Pure (f vx vy)
9494
| x, y -> operator (Map2 (x, y, f))
9595
)
9696

97-
let map' x f = map f x
98-
let map2' x y f = map2 f x y
99-
10097
let pair x y = inj (
10198
match prj x, prj y with
10299
| Pure vx, Pure vy -> Pure (vx, vy)
@@ -115,7 +112,7 @@ let join child = inj (
115112
| child -> operator (Join { child; intermediate = None })
116113
)
117114

118-
let bind x f = join (map f x)
115+
let bind x ~f = join (map ~f x)
119116

120117
(* Management of trace indices *)
121118

@@ -624,8 +621,8 @@ let quick_release root =
624621
flush_or_fail None queue
625622

626623
module Infix = struct
627-
let (>>=) = bind
628-
let (>|=) = map'
624+
let (>>=) x f = bind x ~f
625+
let (>|=) x f = map x ~f
629626
let (<*>) = app
630627
end
631628

lib/lwd/lwd.mli

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,19 @@ val return : 'a -> 'a t
1717
val pure : 'a -> 'a t
1818
(** Alias to {!return} *)
1919

20-
val map : ('a -> 'b) -> 'a t -> 'b t
21-
(** [map f d] is the document that has value [f x] whenever [d] has value [x] *)
20+
val map : 'a t -> f:('a -> 'b) -> 'b t
21+
(** [map d ~f] is the document that has value [f x] whenever [d] has value [x] *)
2222

23-
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
24-
(** [map2 f d1 d2] is the document that has value [f x1 x2] whenever
23+
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
24+
(** [map2 d1 d2 ~f] is the document that has value [f x1 x2] whenever
2525
[d1] has value [x1] and [d2] has value [x2] *)
2626

27-
val map' : 'a t -> ('a -> 'b) -> 'b t
28-
(** Alias to {!map} with arguments flipped *)
29-
30-
val map2' : 'a t -> 'b t -> ('a -> 'b -> 'c) -> 'c t
31-
(** Alias to {!map2} with arguments flipped *)
32-
3327
val join : 'a t t -> 'a t
3428
(** Monadic operator [join d] is the document pointed to by document [d].
3529
This is powerful but potentially costly in case of recomputation.
3630
*)
3731

38-
val bind : 'a t -> ('a -> 'b t) -> 'b t
32+
val bind : 'a t -> f:('a -> 'b t) -> 'b t
3933
(** Monadic bind, a mix of {!join} and {!map} *)
4034

4135
val app : ('a -> 'b) t -> 'a t -> 'b t

lib/lwd/lwd_infix_letop.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let (let$) : 'a Lwd.t -> ('a -> 'b) -> 'b Lwd.t = Lwd.map'
1+
let (let$) : 'a Lwd.t -> ('a -> 'b) -> 'b Lwd.t = Lwd.Infix.(>|=)
22
let (and$) : 'a Lwd.t -> 'b Lwd.t -> ('a * 'b) Lwd.t = Lwd.pair
3-
let (let$*) : 'a Lwd.t -> ('a -> 'b Lwd.t) -> 'b Lwd.t = Lwd.bind
3+
let (let$*) : 'a Lwd.t -> ('a -> 'b Lwd.t) -> 'b Lwd.t = Lwd.Infix.(>>=)
44

55
let ($=) : 'a Lwd.var -> 'a -> unit = Lwd.set
66
let ($<-) : 'a Lwd_table.row -> 'a -> unit = Lwd_table.set

lib/lwd/lwd_seq.ml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,25 @@ let fold ~map ~reduce seq =
462462
| Some other -> Lwd.pure (Some (pure_map_reduce map reduce other))
463463
| None ->
464464
let reducer = ref (Reducer.make ~map ~reduce) in
465-
Lwd.map' seq @@ fun seq ->
466-
let reducer' = Reducer.update !reducer seq in
467-
reducer := reducer';
468-
Reducer.reduce reducer'
465+
Lwd.map seq ~f:begin fun seq ->
466+
let reducer' = Reducer.update !reducer seq in
467+
reducer := reducer';
468+
Reducer.reduce reducer'
469+
end
469470

470471
let fold_monoid map (zero, reduce) seq =
471472
match Lwd.is_pure seq with
472473
| Some Nil -> Lwd.pure zero
473474
| Some other -> Lwd.pure (pure_map_reduce map reduce other)
474475
| None ->
475476
let reducer = ref (Reducer.make ~map ~reduce) in
476-
Lwd.map' seq @@ fun seq ->
477-
let reducer' = Reducer.update !reducer seq in
478-
reducer := reducer';
479-
match Reducer.reduce reducer' with
480-
| None -> zero
481-
| Some x -> x
477+
Lwd.map seq ~f:begin fun seq ->
478+
let reducer' = Reducer.update !reducer seq in
479+
reducer := reducer';
480+
match Reducer.reduce reducer' with
481+
| None -> zero
482+
| Some x -> x
483+
end
482484

483485
let monoid = (empty, concat)
484486

@@ -535,7 +537,7 @@ let to_array x =
535537

536538
let lwd_empty : 'a t Lwd.t = Lwd.pure Nil
537539
let lwd_monoid : 'a. 'a t Lwd.t Lwd_utils.monoid =
538-
(lwd_empty, fun x y -> Lwd.map2 concat x y)
540+
(lwd_empty, fun x y -> Lwd.map2 ~f:concat x y)
539541

540542
let map f seq =
541543
fold_monoid (fun x -> element (f x)) monoid seq
@@ -557,4 +559,4 @@ let seq_bind (seq : 'a seq Lwd.t) (f : 'a -> 'b seq) : 'b seq Lwd.t =
557559
fold_monoid f monoid seq
558560

559561
let lift (seq : 'a Lwd.t seq Lwd.t) : 'a seq Lwd.t =
560-
bind seq (Lwd.map element)
562+
bind seq (Lwd.map ~f:element)

0 commit comments

Comments
 (0)