Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

` operator in OCaml

Tags:

ocaml

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.

like image 329
eatonphil Avatar asked Feb 25 '15 15:02

eatonphil


1 Answers

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.)

like image 108
Jeffrey Scofield Avatar answered Oct 17 '22 13:10

Jeffrey Scofield