Syntax let x : t = β¦ is an argument without an argument of a more general syntax
let f a1 β¦ an : t = β¦
where t is the return type of the function f . The identifier f should be just an identifier, you cannot have a template. You can also write something like
let (x, y) = β¦
Here (x, y) is the pattern. Type annotations can appear in templates, but they must be surrounded by brackets (for example, in expressions), so you need to write
let ((x, y) : coords) = β¦
Please note that this annotation is useless, with the exception of some cosmetic report messages; x and y are still of type int , and (x, y) is of type int * int . If you do not want the coordinates to be of the same type as integers, you need to enter a constructor:
type coords = Coords of int * int let xy = Coords (3, 4)
If you do this, the individual coordinate is still an integer, but the coordinate pair is a constructed object that has its own type. To get the value of one coordinate, the constructor must be included in the pattern matching:
let longitude (c : coords) = match c with Coords (x, y) -> x
source share