F # union syntax discrimination

I am reading Expert F # 4.0 and at some point (p .93) the listfollowing syntax is introduced:

type 'T list =
    | ([])
    | (::) of 'T * 'T list

Although I understand conceptually what is happening here, I do not understand the syntax. Obviously, you can put []either ::between parentheses and they mean something special.

Other characters are not allowed, such as (++)or (||). So what is going on here?

And one more thing - the "operator" of nature (::). Suppose I have the following (strange) type:

type 'T X =
    | None
    | Some of 'T * 'T X
    | (::) of 'T * 'T X

Now I can say:

let x: X<string> = Some ("", None)

but this is not allowed:

let x: X<string> = :: ("", None)
let x: X<string> = (::) ("", None)

So, (::)in fact, something is completely different than Some, although both are cases in a discriminatory association.

+4
1

F # spec (. 8.5) , - , .

- ML. , Cons (x, Cons(y, Cons (z, Empty))) x :: y :: z :: [].

, - ([]) (::). , . , - .

:

let (++) a b = a * b

"" infix:

let x = 5 ++ 6   // x = 30

, - .. f 5 6.

, , , , , , . . 4.1 .

+7

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


All Articles