`operator in OCaml

What does an operator do in OCaml?

let int_of_meth = function | `GET -> 0 | `POST -> 1 | `PUT -> 2 | `DELETE -> 3 | `HEAD -> 4 | `PATCH -> 5 | `OPTIONS -> 6 | _ -> failwith "non standard http verbs not supported" 

I can not find it in the OCaml manual.

+6
source share
1 answer

This ` not an operator. It works at the lexical level (for example, quotation marks for strings) and turns the next character into a "polymorphic variant". See Link given by @Edgar Aroutiounian:

http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual006.html#toc36

Update

In fact, it is scanned as a separate character, as indicated by @gsg. Thus, a polymorphic variant, such as ` Abc , is a syntax construct. I would still argue that this is not an operator in the usual sense.

(Edit: changed to Abc. I never knew that they should be capitalized. For example, the lablgl interface seems to use lowercase sequentially.)

+7
source

Source: https://habr.com/ru/post/982995/


All Articles