Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006500OCamlOCaml standard librarypublic2014-07-28 15:152015-12-09 21:33
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target Version4.03.0+devFixed in Version 
Summary0006500: New functions for bytes/strings
DescriptionSome useful functions to create string (esp. String.init, which avoids the need to go through a bytes than copy it):

String.init: int -> (int -> char) -> string
Bytes.init: int -> (int -> char) -> bytes

Some more useful functions to avoid copying between bytes and string, at least explicitly (this is much lower priority, I'd say):

Buffer.sub_bytes: t -> int -> int -> bytes
Format.print_bytes: bytes -> unit
Format.print_bytes_as: int -> bytes -> unit
Lexing.from_bytes: bytes -> lexbuf
Pervasives.print_bytes_endline: bytes -> unit
Pervasives.prerr_bytes_endline: bytes -> unit
Pervasives.read_line_bytes: unit -> bytes
Pervasives.input_line_bytes: in_channel -> bytes
Scanf.from_bytes: bytes -> in_channel
Stream.of_bytes : bytes -> char t

(There are a few more in Scanf, Printf.)
Attached Filespatch file icon mapi.patch [^] (4,807 bytes) 2014-08-02 13:48 [Show Content]

- Relationships

-  Notes
frisch (developer)
2014-07-28 15:27
edited on: 2014-07-28 15:31

Commit 15029 on 4.02 (15030 on trunk) adds String.init, Bytes.init, Labels couterparts, Stream.of_byte.

gasche (developer)
2014-08-02 13:51

The attached patch implements String.mapi, and Bytes.mapi in passing. If that is all right, I'd like to commit it eventually. I also specified the iteration order of init/map/mapi: in my experience users rely on it anyway, so we cannot change it, and it's better to not worry and just document it from the start.

I think the functions you listed are important and we should provide them to have a smooth transition. I can help with the implementation -- in any case I plan to document Bytes.unsafe_to_string and Bytes.unsafe_of_string, and try to minimize use of the latter.
frisch (developer)
2014-08-06 17:54
edited on: 2014-08-06 17:56

Gabriel: please commit mapi (also updating StringLabels/BytesLabels).

Also, the type bytes is really just an optimized implementation of "char array", and it thus makes sense to have the Bytes module implements all relevant operations from Array. The ones currently missing:

val to_list: bytes -> char list
val of_list: char list -> bytes
val fold_left: ('a -> char -> 'a) -> 'a -> bytes -> 'a
val fold_right: (char -> 'a -> 'a) -> 'bytes -> 'a -> 'a
val {sort, stable_sort, fast_sort}: (char -> char -> int) -> bytes -> unit

We should also consider renaming to Bytes.append. Bytes.concat is a little bit problematic, since Array.concat also exists, but without the delimiter, and we want to keep the same name as String.

doligez (administrator)
2014-08-20 10:24

Most of these function types don't make sense to me: a single "bytes" argument is pretty useless, you should almost always take three arguments: bytes, offset, length.
kaustuv (reporter)
2014-09-10 09:53

Also worth adding: Format.pp_print_bytes. This should then also be a registered printer in the toplevel if it is invoked with -safe-string.

- Issue History
Date Modified Username Field Change
2014-07-28 15:15 frisch New Issue
2014-07-28 15:15 frisch Description Updated View Revisions
2014-07-28 15:27 frisch Note Added: 0011932
2014-07-28 15:31 frisch Note Edited: 0011932 View Revisions
2014-08-02 13:48 gasche File Added: mapi.patch
2014-08-02 13:51 gasche Note Added: 0011968
2014-08-06 17:54 frisch Note Added: 0011983
2014-08-06 17:56 frisch Note Edited: 0011983 View Revisions
2014-08-20 10:24 doligez Note Added: 0012028
2014-08-20 10:24 doligez Status new => feedback
2014-08-20 10:24 doligez Target Version 4.02.0+dev => 4.02.1+dev
2014-09-04 00:25 doligez Target Version 4.02.1+dev => undecided
2014-09-10 09:53 kaustuv Note Added: 0012100
2014-09-14 21:33 doligez Target Version undecided => 4.02.2+dev / +rc1
2015-01-15 00:53 doligez Tag Attached: patch
2015-03-11 21:18 doligez Target Version 4.02.2+dev / +rc1 => 4.03.0+dev
2015-12-09 21:33 xleroy Severity minor => feature

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker