When using abbreviations / aliases like, why should I use the fun keyword?

In the example below, I am using type abbreviation. Why should I use the fun keyword and not name it without the fun keyword?

type AdditionFunction = int->int->int

let f:AdditionFunction = fun a b -> a + b
+4
source share
1 answer

Because otherwise you cannot annotate it with a type AdditionFunction. You need to put this value, which is of type int -> int -> int, and the way the F # syntax works is that you have no way to do this using the let-bound style.

Your options:

let f : int -> int -> int = 
   fun a b -> ...

let f a : int -> int = 
   fun b -> ...

let f a b : int = 
   ...    

and only the first has a type that you could replace with an alias.

. int -> int -> int, , AdditionFunction.

- . , , .

+6

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


All Articles