Skip to content

The Great Renaming, Chapter 10: map renaming#380

Merged
jmid merged 2 commits intoc-cube:mainfrom
jmid:map-renaming
Dec 4, 2025
Merged

The Great Renaming, Chapter 10: map renaming#380
jmid merged 2 commits intoc-cube:mainfrom
jmid:map-renaming

Conversation

@jmid
Copy link
Collaborator

@jmid jmid commented Dec 4, 2025

Still wrapping up loose ends in the renaming adventure, we come across map combinators.

The status is:

Combinator name QCheck.Gen QCheck.arbitrary QCheck2.Gen
map ('a -> 'b) -> 'a t -> 'b t ?rev:('b -> 'a) -> ('a -> 'b) -> 'a arbitrary -> 'b arbitrary ('a -> 'b) -> 'a t -> 'b t
map2 ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t - ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
map3 ('a -> 'b -> 'c -> 'd) -> ... -> 'd t - ('a -> 'b -> 'c -> 'd) -> ... -> 'd t
map4 ('a -> 'b -> 'c -> 'd -> 'e) -> ... -> 'e t - ('a -> 'b -> 'c -> 'd -> 'e) -> ... -> 'e t
map5 ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> ... -> 'f t - ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> ... -> 'f t
map_keep_input ('a -> 'b) -> 'a t -> ('a * 'b) t ?print:'b Print.t -> ?small:('b -> int) -> ('a -> 'b) -> 'a arbitrary -> ('a * 'b) arbitrary -
map_same_type - ('a -> 'a) -> 'a arbitrary -> 'a arbitrary -

where I have abbreviated somel map signatures in an attempt to make things fit:

  • map3 : ('a -> 'b -> 'c -> 'd) -> 'a t -> 'b t -> 'c t -> 'd t
  • map4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t
  • map5 : ('a -> 'b -> 'c -> 'd -> 'e -> 'f) -> 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t

Observations

  • map* is hard to preserve shrinkers, printers, hence the omissions from QCheck.arbitrary are natural
    • this is also the reason for the optional rev parameter in QCheck.map
  • map_same_type only occurs in QCheck.arbitrary - but for QCheck.Gen and QCheck2.Gen map is equivalent
  • map_keep_input is missing from QCheck2.Gen for consistency

This PR therefore adds the missing QCheck2.Gen.map_keep_input : ('a -> 'b) -> 'a t -> ('a * 'b) t, while leaving the rest as is.

@jmid jmid merged commit 937e057 into c-cube:main Dec 4, 2025
24 checks passed
@jmid jmid deleted the map-renaming branch December 4, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant