Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
- Add `QCheck.Gen.int_pos_mid` alias for `QCheck.Gen.nat`
- Add `QCheck.int_pos_mid` alias for `QCheck.nat`
- Add `QCheck2.Gen.int_pos_mid` and alias `QCheck2.Gen.nat_mid`
- Renamed monadic and applicative generator combinators:
- Add missing `QCheck.Gen.bind` for consistency
- Add missing `QCheck.Gen.ap` for consistency


## 0.27 (2025-10-31)
Expand Down
7 changes: 4 additions & 3 deletions src/core/QCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ module Gen = struct
let return x _st = x
let pure = return

let (>>=) gen f st =
f (gen st) st
let bind gen f st = f (gen st) st
let (>>=) = bind

let (<*>) f x st = f st (x st)
let ap f x st = f st (x st)
let (<*>) = ap
let map f x st = f (x st)
let map2 f x y st = f (x st) (y st)
let map3 f x y z st = f (x st) (y st) (z st)
Expand Down
16 changes: 12 additions & 4 deletions src/core/QCheck.mli
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,22 @@ module Gen : sig
(** Synonym for {!return}
@since 0.8 *)

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val bind : 'a t -> ('a -> 'b t) -> 'b t
(** Monadic bind for writing dependent generators. First generates an ['a] and then
passes it to the given function, to generate a ['b]. *)
passes it to the given function, to generate a ['b].

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
(** Infix operator for composing a function generator and an argument generator
@since NEXT_RELEASE *)

val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
(** Synonym for {!bind} since NEXT_RELEASE *)

val ap : ('a -> 'b) t -> 'a t -> 'b t
(** Applicative operator for composing a function generator and an argument generator
into a result generator. *)

val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
(** Synonym for {!ap} since NEXT_RELEASE *)

val map : ('a -> 'b) -> 'a t -> 'b t
(** [map f g] transforms a generator [g] by applying [f] to each generated element. *)

Expand Down