val find_and_sum : ('a, int) Hashtbl.t -> 'a -> 'a -> int option = <fun>
Users can also define and operators:
module ZipSeq = structtype 'a t = 'a Seq.t
open Seq
letrec return x =
fun () -> Cons(x, return x)
letrec prod a b =
fun () ->
match a (), b () with
| Nil, _ | _, Nil -> Nil
| Cons(x, a), Cons(y, b) -> Cons((x, y), prod a b)
let ( let+ ) f s = map s f
let ( and+ ) a b = prod a b
end
module ZipSeq :
sigtype 'a t = 'a Seq.t
val return : 'a -> 'a Seq.t
val prod : 'a Seq.t -> 'b Seq.t -> ('a * 'b) Seq.t
val ( let+ ) : 'a Seq.t -> ('a -> 'b) -> 'b Seq.t
val ( and+ ) : 'a Seq.t -> 'b Seq.t -> ('a * 'b) Seq.t
end
to support the syntax:
open ZipSeq
let sum3 z1 z2 z3 =
let+ x1 = z1
and+ x2 = z2
and+ x3 = z3 in
x1 + x2 + x3
val sum3 : int Seq.t -> int Seq.t -> int Seq.t -> int Seq.t = <fun>
val sum3 : int Seq.t -> int Seq.t -> int Seq.t -> int Seq.t = <fun>
23.1 Short notation for variable bindings (let-punning)
(Introduced in 4.13.0)
When the expression being bound is a variable, it can be convenient to
use the shorthand notation let+ x in ..., which expands to let+ x = x in .... This notation, also known as let-punning, allows the
sum3 function above can be written more concisely as:
open ZipSeq
let sum3 z1 z2 z3 =
let+ z1 and+ z2 and+ z3 in
z1 + z2 + z3
val sum3 : int Seq.t -> int Seq.t -> int Seq.t -> int Seq.t = <fun>
This notation is also supported for extension nodes, expanding
let%foo x in ... to let%foo x = x in .... However, to avoid
confusion, this notation is not supported for plain let bindings.