review 2
This commit is contained in:
parent
dbb6fbd8e6
commit
c17a749078
@ -307,7 +307,7 @@ At the moment, recursive function are limited to one (possibly tupled) parameter
|
|||||||
limited to tail recursion (i.e the recursive call should be the last expression of the function)
|
limited to tail recursion (i.e the recursive call should be the last expression of the function)
|
||||||
|
|
||||||
<Syntax syntax="pascaligo">
|
<Syntax syntax="pascaligo">
|
||||||
In PascaLigo recursive functions are defined using the "recursive" keyword
|
In PascaLigo recursive functions are defined using the `recursive` keyword
|
||||||
|
|
||||||
```pascaligo group=d
|
```pascaligo group=d
|
||||||
recursive function sum (const n : int; const acc: int) : int is
|
recursive function sum (const n : int; const acc: int) : int is
|
||||||
@ -318,7 +318,7 @@ recursive function fibo (const n: int; const n_1: int; const n_0 :int) : int is
|
|||||||
```
|
```
|
||||||
</Syntax>
|
</Syntax>
|
||||||
<Syntax syntax="cameligo">
|
<Syntax syntax="cameligo">
|
||||||
In CameLigo recursive functions are defined using the "rec" keyword
|
In CameLigo recursive functions are defined using the `rec` keyword
|
||||||
|
|
||||||
```cameligo group=d
|
```cameligo group=d
|
||||||
let rec sum ((n,acc):int * int) : int =
|
let rec sum ((n,acc):int * int) : int =
|
||||||
@ -329,7 +329,7 @@ let rec fibo ((n,n_1,n_0):int*int*int) : int =
|
|||||||
```
|
```
|
||||||
</Syntax>
|
</Syntax>
|
||||||
<Syntax syntax="reasonligo">
|
<Syntax syntax="reasonligo">
|
||||||
In ReasonLigo recursive functions are defined using the "rec" keyword
|
In ReasonLigo recursive functions are defined using the `rec` keyword
|
||||||
|
|
||||||
```reasonligo group=d
|
```reasonligo group=d
|
||||||
let rec sum = ((n, acc) : (int,int)): int =>
|
let rec sum = ((n, acc) : (int,int)): int =>
|
||||||
|
@ -184,17 +184,6 @@ module Errors = struct
|
|||||||
] in
|
] in
|
||||||
error ~data title message
|
error ~data title message
|
||||||
|
|
||||||
let _untyped_recursive_function var =
|
|
||||||
let title () = "" in
|
|
||||||
let message () =
|
|
||||||
Format.asprintf "\nUntyped recursive function \
|
|
||||||
are not supported yet.\n" in
|
|
||||||
let param_loc = var.Region.region in
|
|
||||||
let data = [
|
|
||||||
("location",
|
|
||||||
fun () -> Format.asprintf "%a" Location.pp_lift @@ param_loc)]
|
|
||||||
in error ~data title message
|
|
||||||
|
|
||||||
(* Logging *)
|
(* Logging *)
|
||||||
|
|
||||||
let simplifying_instruction t =
|
let simplifying_instruction t =
|
||||||
@ -751,26 +740,24 @@ and simpl_fun_expression :
|
|||||||
let statements = [] in
|
let statements = [] in
|
||||||
(match param.value.inside with
|
(match param.value.inside with
|
||||||
a, [] -> (
|
a, [] -> (
|
||||||
let%bind input = simpl_param a in
|
let%bind input = simpl_param a in
|
||||||
let (binder , input_type) = input in
|
let (binder , input_type) = input in
|
||||||
let%bind instructions = simpl_statement_list statements in
|
let%bind instructions = simpl_statement_list statements in
|
||||||
let%bind result = simpl_expression return in
|
let%bind result = simpl_expression return in
|
||||||
let%bind output_type = simpl_type_expression ret_type in
|
let%bind output_type = simpl_type_expression ret_type in
|
||||||
let body = instructions in
|
let body = instructions in
|
||||||
let%bind result =
|
let%bind result =
|
||||||
let aux prec cur = cur (Some prec) in
|
let aux prec cur = cur (Some prec) in
|
||||||
bind_fold_right_list aux result body in
|
bind_fold_right_list aux result body in
|
||||||
let binder = Var.of_name binder in
|
let binder = Var.of_name binder in
|
||||||
let fun_type = t_function input_type output_type in
|
let fun_type = t_function input_type output_type in
|
||||||
let expression : expression =
|
let expression = match kwd_recursive with
|
||||||
e_lambda ~loc binder (Some input_type)(Some output_type) result in
|
| None -> e_lambda ~loc binder (Some input_type)(Some output_type) result
|
||||||
let%bind expression = match kwd_recursive with
|
| Some _ -> e_recursive ~loc binder fun_type
|
||||||
None -> ok @@ expression |
|
@@ {binder;input_type=Some input_type; output_type= Some output_type; result}
|
||||||
Some _ -> ok @@ e_recursive ~loc binder fun_type
|
in
|
||||||
@@ {binder;input_type=Some input_type; output_type= Some output_type; result}
|
ok (Some fun_type , expression)
|
||||||
in
|
)
|
||||||
ok (Some fun_type , expression)
|
|
||||||
)
|
|
||||||
| lst -> (
|
| lst -> (
|
||||||
let lst = npseq_to_list lst in
|
let lst = npseq_to_list lst in
|
||||||
(* TODO wrong, should be fresh? *)
|
(* TODO wrong, should be fresh? *)
|
||||||
@ -795,11 +782,9 @@ and simpl_fun_expression :
|
|||||||
let aux prec cur = cur (Some prec) in
|
let aux prec cur = cur (Some prec) in
|
||||||
bind_fold_right_list aux result body in
|
bind_fold_right_list aux result body in
|
||||||
let fun_type = t_function input_type output_type in
|
let fun_type = t_function input_type output_type in
|
||||||
let expression : expression =
|
let expression = match kwd_recursive with
|
||||||
e_lambda ~loc binder (Some input_type)(Some output_type) result in
|
| None -> e_lambda ~loc binder (Some input_type)(Some output_type) result
|
||||||
let%bind expression = match kwd_recursive with
|
| Some _ -> e_recursive ~loc binder fun_type
|
||||||
None -> ok @@ expression |
|
|
||||||
Some _ -> ok @@ e_recursive ~loc binder fun_type
|
|
||||||
@@ {binder;input_type=Some input_type; output_type= Some output_type; result}
|
@@ {binder;input_type=Some input_type; output_type= Some output_type; result}
|
||||||
in
|
in
|
||||||
ok (Some fun_type , expression)
|
ok (Some fun_type , expression)
|
||||||
|
@ -3,7 +3,7 @@ open Trace
|
|||||||
|
|
||||||
module Errors = struct
|
module Errors = struct
|
||||||
let recursive_call_is_only_allowed_as_the_last_operation name loc () =
|
let recursive_call_is_only_allowed_as_the_last_operation name loc () =
|
||||||
let title = (thunk ("Recursive call is only allowed as the last operation")) in
|
let title = (thunk ("Recursion must be achieved through tail-calls only")) in
|
||||||
let message () = "" in
|
let message () = "" in
|
||||||
let data = [
|
let data = [
|
||||||
("function" , fun () -> Format.asprintf "%a" PP.expression_variable name);
|
("function" , fun () -> Format.asprintf "%a" PP.expression_variable name);
|
||||||
|
Loading…
Reference in New Issue
Block a user