What does the ` 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't find it in the OCaml manual.
This `
is not really an operator. It works at the lexical level (like quotes for strings) and makes the following symbol into a "polymorphic variant". See the link given by @Edgar Aroutiounian:
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual006.html#toc36
Update
Actually, `
is scanned as a separate symbol as noted by @gsg. So a polymorphic variant like ` Abc
is a syntactic construct. I would still claim it's not an operator in the usual sense.
(Edit: changed to Abc. I never knew they were supposed to be capitalized. For example, the lablgl interface seems to use lower case consistently.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With