This commit is contained in:
Pierre-Emmanuel Wulfman 2020-03-11 17:04:49 +01:00
parent dbb6fbd8e6
commit c17a749078
3 changed files with 25 additions and 40 deletions

View File

@ -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 =>

View File

@ -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 =
@ -762,11 +751,9 @@ and simpl_fun_expression :
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 |
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)
@ -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)

View File

@ -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);