Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is OCaml's alternative string syntax {|...|} documented?

OCaml's syntax for string literals

let s = "..."

is explained in the manual at the expected position:

https://caml.inria.fr/pub/docs/manual-ocaml/lex.html#s:stringliteral

However, OCaml has an alternative syntax for string literals which is especially handy for regular expressions and multi-line strings:

let s = {|...|}
let s = {foo|...|foo}

Where is that documented?

like image 714
vog Avatar asked Sep 02 '18 09:09

vog


People also ask

How do I test a string in OCaml?

You can compare strings with the usal comparison operators: = , <> , < , <= , > , >= . You can also use the compare function, which returns -1 if the first string is less than the second, 1 if the first string is greater than the second, and 0 if they are equal.

What is a string in OCaml?

Strings. A string s of length n is an indexable and immutable sequence of n bytes. For historical reasons these bytes are referred to as characters. The semantics of string functions is defined in terms of indices and positions.

How do I concatenate strings in OCaml?

How do I combine two strings in Ocaml? The (^) binary operator concatenates two strings.

How do you escape in OCaml?

According to the lexical conventions of OCaml, characters different from \ and " can be enclosed in single quotes and appear in strings. The special characters \ and " are represented in these contexts by their escape sequences. The escape sequence \\ denotes the character \ and \" denotes the character " .


1 Answers

To answer this question myself, the syntax was originally described in the extensions chapter of the OCaml manual:

  • Section: 8.18 Quoted strings
  • https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec264

Thanks to glennsl and octachron for pointing this out.

Update: Meanwhile it has been moved to the expected, more visible, places:

  • https://caml.inria.fr/pub/docs/manual-ocaml/lex.html#sss:stringliterals
  • https://caml.inria.fr/pub/docs/manual-ocaml/coreexamples.html#s:datatypes
like image 110
vog Avatar answered Sep 24 '22 18:09

vog