From: Alain Frisch <alain@frisch.fr>
To: Gerd Stolpmann <info@gerd-stolpmann.de>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Immutable strings
Date: Mon, 21 Jul 2014 17:06:29 +0200 [thread overview]
Message-ID: <53CD2C75.8090208@frisch.fr> (raw)
In-Reply-To: <1404501528.4384.4.camel@e130>
On 07/04/2014 09:18 PM, Gerd Stolpmann wrote:
> http://blog.camlcity.org/blog/bytes1.html
Coming back to motivating example of this post.
Lexing provides:
val from_channel : in_channel -> lexbuf
val from_string : string -> lexbuf
val from_function : (bytes -> int -> int) -> lexbuf
In particular, from_function expects you to write to a buffer, so it's
pretty clear that its callback must accept a "bytes", not a "string".
There is no place for a (string -> int -> int) -> lexbuf function.
Concerning from_string: this function copies the string to an internal
buffer. This is purely implemented on the OCaml side without any unsafe
features. We could avoid this copy because we know that the generated
lexers won't actually modify the buffer in that case, but it would be
very difficult to do this without using an unsafe feature, even if we
had some sort of generalization of bytes and string. We would instead
need a completely different implementation (which would not use
"stringable" to make the "source" (string or "stream") explicit in the
lexbuf datastructure.
We could also provide an extra from_bytes function, but it can currently
be implemented by composing Bytes.to_string and Lexing.from_string. Are
you concerned only by the performance overhead of this approach (two
copies)? If so, the same argument would apply to the current
implementation of from_string, and we would need to switch to a
different approach, for which it's not clear that "stringable" would be
a big help (see above). Before doing anything like that, it would be
interesting to evaluate the exact overhead. It could very well be
negligible/acceptable for most cases compared to the cost of actual lexing.
-- Alain
next prev parent reply other threads:[~2014-07-21 15:06 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-04 19:18 Gerd Stolpmann
2014-07-04 20:31 ` Anthony Tavener
2014-07-04 20:38 ` Malcolm Matalka
2014-07-04 23:44 ` Daniel Bünzli
2014-07-05 11:04 ` Gerd Stolpmann
2014-07-16 11:38 ` Damien Doligez
2014-07-04 21:01 ` Markus Mottl
2014-07-05 11:24 ` Gerd Stolpmann
2014-07-08 13:23 ` Jacques Garrigue
2014-07-08 13:37 ` Alain Frisch
2014-07-08 14:04 ` Jacques Garrigue
2014-07-28 11:14 ` Goswin von Brederlow
2014-07-28 15:51 ` Markus Mottl
2014-07-29 2:54 ` Yaron Minsky
2014-07-29 9:46 ` Goswin von Brederlow
2014-07-29 11:48 ` John F. Carr
2014-07-07 12:42 ` Alain Frisch
2014-07-08 12:24 ` Gerd Stolpmann
2014-07-09 13:54 ` Alain Frisch
2014-07-09 18:04 ` Gerd Stolpmann
2014-07-10 6:41 ` Nicolas Boulay
2014-07-14 17:40 ` Richard W.M. Jones
2014-07-08 18:15 ` mattiasw
2014-07-08 19:24 ` Daniel Bünzli
2014-07-08 19:27 ` Raoul Duke
2014-07-09 14:15 ` Daniel Bünzli
2014-07-14 17:45 ` Richard W.M. Jones
2014-07-21 15:06 ` Alain Frisch [this message]
[not found] ` <20140722.235104.405798419265248505.Christophe.Troestler@umons.ac.be>
2014-08-29 16:30 ` Damien Doligez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53CD2C75.8090208@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@inria.fr \
--cc=info@gerd-stolpmann.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox