F # recursive function output?

I am very new to programming in F #. I am looking for an answer about why the next recursive function will exit when condition n = 0 is reached. Does the syntax "then 1" have a special value equal to EXIT?

let rec factorial n = 
    if n = 0 
    then 1 
    else n * factorial (n - 1)
+4
source share
1 answer

Functional programming languages are expression - oriented rather than operator-oriented. This means that all of this is an expression that can be evaluated into a value.

The structures of the control flow if, and matchalso are valid expressions. The compiler checks that all branches of these expressions return the same type.

, F # if true then 1 else 0 true ? 1 : 0.

, "" . . ( n + 1) if/then/else.

+6

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


All Articles