F#入门-附录6 运算符的优先顺序

运算符的优先顺序
参考
                  The F# 1.9.6 Draft Language Specification
                         4.4 Precedence and Operators

         右侧书写的是运算符的结合方法。
                  %right 右结合
                  %left 左结合
                  %nonassoc 无结合
         越往下优先级越高
         as                                           %right
         when                                      %right
         |                                              %left
         ;                                              %right
         let                                           %nonassoc
         function, fun, match, try          %nonassoc
         if                                             %nonassoc
         ->                                           %right
         :=                                           %right
         ,                                             %nonassoc
         or ||                                       %left
         & &&                                      %left
         <OP >OP $OP = |OP &OP       %left
         ^OP                                        %right
         ::                                             %right
         :?> :?                                      %nonassoc
         -OP +OP                                 %left
         *OP /OP %OP                         %left
         **OP                                       %right
         "f x" "lazy x" "assert x"          %left
         !OP ?OP ~OP -OP +OP           %left
         .                                             %left
         f(x)                                        %left  - high precedence application
         f<types>                              %left  - type application


    这张表中“OP标识”与某个变量表示定义自身变量时的优先顺序与结合型(由运算符的首文字决定)。
    例如

用户定义的运算符的结合性
let ( <<@ ) x y = x ** y;; //x ** y 为x的y次方
let ( ^^@ ) x y = x ** y;;

> 3. <<@ 3. <<@ 3.;;
         val it : float = 19683.0
> 3. ^^@ 3. ^^@ 3.;;
         val it : float = 7.625597485e+12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值