Rawley Fowler
Rawley Fowler

Reputation: 2584

What is the :> operator?

I was looking through the Dream source code when I stumbled upon an operator (probably defined in a package) that I have never seen before:

let method_ =
  match (method_ :> Method.method_ option) with
  | None -> `GET
  | Some method_ -> method_

What is the :> operator, where does it come from, what does it do?

Upvotes: 2

Views: 81

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

:> is a builtin operator in the typing sub-language that asserts a subtyping relation. So it's not from a package.

In this particular case it is saying that method_, which probably has some more specific type, should be treated as if it is of type Method.method_ option. The type checker will first verify that the type of method_ is a subtype of the specified type.

This is documented in Chapter 9, Section 7.7 of the OCaml manual, where the construct is called a "coercion".

Upvotes: 6

Related Questions