Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds missing functions to *Labels modules #875

Merged
merged 1 commit into from Jan 3, 2017

Conversation

little-arhat
Copy link
Contributor

@little-arhat little-arhat commented Oct 25, 2016

This fix make it possible to use labeled modules as drop-in replacement with
open StdLabels.

Added signatures:

(* arrayLabels.mli *)
val iter2 : f:('a -> 'b -> unit) -> 'a array -> 'b array -> unit
val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array

(* bytesLabels.mli *)
val extend : bytes -> left:int -> right:int -> bytes
val blit_string :
val cat : bytes -> bytes -> bytes
val uppercase_ascii : bytes -> bytes
val lowercase_ascii : bytes -> bytes
val capitalize_ascii : bytes -> bytes
val uncapitalize_ascii : bytes -> bytes
val equal: t -> t -> bool

(* listLabels.mli *)
val compare_lengths : 'a list -> 'b list -> int
val compare_length_with : 'a list -> len:int -> int
val cons : 'a -> 'a list -> 'a list

(* moreLabels.Hashtbl *)
val is_randomized : unit -> bool

(* stringLabels.mli *)
val uppercase_ascii : string -> string
val lowercase_ascii : string -> string
val capitalize_ascii : string -> string
val uncapitalize_ascii : string -> string
val equal: t -> t -> bool
val split_on_char: sep:char -> string -> string list

@gasche
Copy link
Member

gasche commented Oct 25, 2016

In principle I agree that keeping the *Labels module on par is a good thing.

Now the nitpicking details. Would we want to have labels on some of the several-arguments function? Here are some potential ideas (but I'm not saying they should absolutely be applied):

val compare_length_with : 'a list -> len:int -> bool
val split_on_char: sep:char -> string -> string list

@garrigue
Copy link
Contributor

Thank you very much for these additions.
Keeping the *Labels modules on par is not just a good thing, it is actually a requirement: open StdLabels and open MoreLabels should add labels to some functions, without hiding anything.

I agree with @gasche on the labelling of compare_length_with and split_on_char, which is coherent with the rest of StdLabels.

@little-arhat
Copy link
Contributor Author

@gasche, @garrigue I've added labels to these two functions.

By the way, I couldn't find any tests checking compatibility of labeled and non-labeled modules. We could miss to add new functions again in the future without them. Should we add tests for that? The easiest way I could think of would be comparing .mli files, but maybe there is some clever way to check this with type-checker and include module type?

@damiendoligez
Copy link
Member

It should be easy with a sed script that creates a .ml file, but is there a more elegant way?

@Drup
Copy link
Contributor

Drup commented Oct 26, 2016

module L : module type of List = ListLabels

for each module, compiled with -nolabels ?

@little-arhat
Copy link
Contributor Author

@Drup great! used your idea to add simple tests.

include module type of Hashtbl
with type statistics := Indirection.t
end
module H : HS = MoreLabels.Hashtbl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module type of struct include Hashtbl end if you want to preserve type equalities. Not sure if that's going to be enough since the fields are not re-exported in MoreLabels.Hashtbl ... but they probably should be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this, same error ...Their kinds differ..

@gasche
Copy link
Member

gasche commented Oct 27, 2016

@damiendoligez do we want this in 4.04? I'm ready to release a new version of Batteries with 4.04 compatibility, but if we decide to take this one in I would wait for it first.

@alainfrisch
Copy link
Contributor

I'm against changing the stdlib a few hours/days before a release. People are supposed to start adapting their libraries when we issue release candidates, and if we start changing things (which can break code in the wild) after release candidates and just before the release, it will reduce people's incentive to play with release candidates in the future. (Of course, this is a bit rhetorical here, since you are also a maintainer of Batteries.)

Not being able to use the most recent additions of stdlib in the *Labels versions is certainly not a critical bug that cannot wait until the next release (which should be out in about 3 months, right?).

@gasche
Copy link
Member

gasche commented Oct 27, 2016

I think that's a fair argument.

@damiendoligez
Copy link
Member

which should be out in about 3 months, right?

What?

@alainfrisch
Copy link
Contributor

I thought 4.05 should be frozen in January 2017. So it would be a bit more than 3 months for the release, but hopefully not much more (I know, I'm dreaming...).

@damiendoligez
Copy link
Member

I thought 4.05 should be frozen in January 2017.

February, so it'll be frozen, not out, in 3 months.

@alainfrisch
Copy link
Contributor

Please Damien let me dream a bit about the delay between freeze and release going down at some point...

@alainfrisch
Copy link
Contributor

alainfrisch commented Nov 4, 2016

Coming back to the topic of this PR. Would it be a good opportunity to change the doc strings in *Labels modules to refer to the real module names? (e.g. refer to ArrayLabels.iter2 as ArrayLabels.iter2, not Labels.iter2)

[EDIT] I see that these modules are supposed to be used through open StdLabels. If we stick to this style, the "deprecated" messages in this PR should refer to Array.foo, not ArrayLabels.foo; and also the doc for split_on_char. I've no strong opinion on which is best, but let's be consistent.

This fix make it possible to use labeled modules as drop-in replacement with
`open StdLabels`.

Added signatures:

```ocaml
(* arrayLabels.mli *)
val iter2 : f:('a -> 'b -> unit) -> 'a array -> 'b array -> unit
val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array

(* bytesLabels.mli *)
val extend : bytes -> left:int -> right:int -> bytes
val blit_string :
val cat : bytes -> bytes -> bytes
val uppercase_ascii : bytes -> bytes
val lowercase_ascii : bytes -> bytes
val capitalize_ascii : bytes -> bytes
val uncapitalize_ascii : bytes -> bytes
val equal: t -> t -> bool

(* listLabels.mli *)
val compare_lengths : 'a list -> 'b list -> int
val compare_length_with : 'a list -> len:int -> int
val cons : 'a -> 'a list -> 'a list

(* moreLabels.Hashtbl *)
val is_randomized : unit -> bool

(* stringLabels.mli *)
val uppercase_ascii : string -> string
val lowercase_ascii : string -> string
val capitalize_ascii : string -> string
val uncapitalize_ascii : string -> string
val equal: t -> t -> bool
val split_on_char: sep:char -> string -> string list
```
@little-arhat
Copy link
Contributor Author

As per @alainfrisch suggestions, fixed all docs and deprecation warnings in *Labels.

@little-arhat
Copy link
Contributor Author

Is everything OK with this patch now, or there are some other suggestions to improve it?
Thanks.

@alainfrisch alainfrisch merged commit 4da2b30 into ocaml:trunk Jan 3, 2017
@alainfrisch
Copy link
Contributor

Thanks for the reminder and the nice contribution.

camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
This fix makes it possible to use labeled modules as drop-in replacement with
`open StdLabels`.

Added signatures:

```ocaml
(* arrayLabels.mli *)
val iter2 : f:('a -> 'b -> unit) -> 'a array -> 'b array -> unit
val map2 : f:('a -> 'b -> 'c) -> 'a array -> 'b array -> 'c array

(* bytesLabels.mli *)
val extend : bytes -> left:int -> right:int -> bytes
val blit_string :
val cat : bytes -> bytes -> bytes
val uppercase_ascii : bytes -> bytes
val lowercase_ascii : bytes -> bytes
val capitalize_ascii : bytes -> bytes
val uncapitalize_ascii : bytes -> bytes
val equal: t -> t -> bool

(* listLabels.mli *)
val compare_lengths : 'a list -> 'b list -> int
val compare_length_with : 'a list -> len:int -> int
val cons : 'a -> 'a list -> 'a list

(* moreLabels.Hashtbl *)
val is_randomized : unit -> bool

(* stringLabels.mli *)
val uppercase_ascii : string -> string
val lowercase_ascii : string -> string
val capitalize_ascii : string -> string
val uncapitalize_ascii : string -> string
val equal: t -> t -> bool
val split_on_char: sep:char -> string -> string list
```
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Oct 25, 2022
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
* Add link to API in /releases

* Use same wording as in docs navbar

---------

Co-authored-by: Cuihtlauac ALVARADO <cuihtmlauac@tarides.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants