@@ -3563,6 +3563,9 @@ and is_automatic_curried_application env funct =
3563
3563
| Tarrow _ -> true
3564
3564
| _ -> false
3565
3565
3566
+ (* * This is ad-hoc translation for unifying specific primitive operations
3567
+ See [Unified_ops] module for detailed explanation.
3568
+ *)
3566
3569
and translate_unified_ops (env : Env.t ) (funct : Typedtree.expression )
3567
3570
(sargs : sargs ) : (targs * Types.type_expr) option =
3568
3571
match funct.exp_desc with
@@ -3601,7 +3604,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
3601
3604
let rhs = type_exp env rhs_expr in
3602
3605
let rhs_type = expand_head env rhs.exp_type in
3603
3606
let lhs, rhs, result_type =
3604
- (* rule 1. *)
3607
+ (* Rule 1. Try unifying to lhs *)
3605
3608
match (lhs_type.desc, specialization) with
3606
3609
| Tconstr (path , _ , _ ), _ when Path. same path Predef. path_int ->
3607
3610
let rhs = type_expect env rhs_expr Predef. type_int in
@@ -3623,7 +3626,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
3623
3626
let rhs = type_expect env rhs_expr Predef. type_string in
3624
3627
(lhs, rhs, Predef. type_string)
3625
3628
| _ -> (
3626
- (* rule 2. *)
3629
+ (* Rule 2. Try unifying to rhs *)
3627
3630
match (rhs_type.desc, specialization) with
3628
3631
| Tconstr (path , _ , _ ), _ when Path. same path Predef. path_int ->
3629
3632
let lhs = type_expect env lhs_expr Predef. type_int in
@@ -3645,7 +3648,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
3645
3648
let lhs = type_expect env lhs_expr Predef. type_string in
3646
3649
(lhs, rhs, Predef. type_string)
3647
3650
| _ ->
3648
- (* rule 3. *)
3651
+ (* Rule 2. Fallback to int *)
3649
3652
let lhs = type_expect env lhs_expr Predef. type_int in
3650
3653
let rhs = type_expect env rhs_expr Predef. type_int in
3651
3654
(lhs, rhs, Predef. type_int))
0 commit comments