summaryrefslogtreecommitdiff
path: root/src/Cps.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cps.ml')
-rw-r--r--src/Cps.ml48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/Cps.ml b/src/Cps.ml
index 2d7dd2be..c2c0363b 100644
--- a/src/Cps.ml
+++ b/src/Cps.ml
@@ -22,25 +22,25 @@ type sexpr = SOne | SList of sexpr list
type eval_result = SA.expression option
-type m_fun = C.eval_ctx -> eval_result
(** Continuation function *)
+type m_fun = C.eval_ctx -> eval_result
-type cm_fun = m_fun -> m_fun
(** Continuation taking another continuation as parameter *)
+type cm_fun = m_fun -> m_fun
-type typed_value_m_fun = V.typed_value -> m_fun
(** Continuation taking a typed value as parameter - TODO: use more *)
+type typed_value_m_fun = V.typed_value -> m_fun
-type typed_value_cm_fun = V.typed_value -> cm_fun
(** Continuation taking another continuation as parameter and a typed
value as parameter.
*)
+type typed_value_cm_fun = V.typed_value -> cm_fun
-type st_m_fun = statement_eval_res -> m_fun
(** Type of a continuation used when evaluating a statement *)
+type st_m_fun = statement_eval_res -> m_fun
-type st_cm_fun = st_m_fun -> m_fun
(** Type of a continuation used when evaluating a statement *)
+type st_cm_fun = st_m_fun -> m_fun
(** Convert a unit function to a cm function *)
let unit_to_cm_fun (f : C.eval_ctx -> unit) : cm_fun =
@@ -65,9 +65,9 @@ let comp_unit (f : cm_fun) (g : C.eval_ctx -> unit) : cm_fun =
let comp_update (f : cm_fun) (g : C.eval_ctx -> C.eval_ctx) : cm_fun =
comp f (update_to_cm_fun g)
-(** This is just a test, to check that [comp] is general enough to handle a case
+(** This is just a test, to check that {!comp} is general enough to handle a case
where a function must compute a value and give it to the continuation.
- It happens for functions like [eval_operand].
+ It happens for functions like {!InterpreterExpressions.eval_operand}.
Keeping this here also makes it a good reference, when one wants to figure
out the signatures he should use for such a composition.
@@ -79,8 +79,8 @@ let comp_ret_val (f : (V.typed_value -> m_fun) -> m_fun)
let apply (f : cm_fun) (g : m_fun) : m_fun = fun ctx -> f g ctx
let id_cm_fun : cm_fun = fun cf ctx -> cf ctx
-(** If we have a list of [inputs] of type `'a list` and a function [f] which
- evaluates one element of type `'a` to compute a result of type `'b` before
+(** If we have a list of [inputs] of type ['a list] and a function [f] which
+ evaluates one element of type ['a] to compute a result of type ['b] before
giving it to a continuation, the following function performs a fold operation:
it evaluates all the inputs one by one by accumulating the results in a list,
and gives the list to a continuation.
@@ -101,7 +101,7 @@ let fold_left_apply_continuation (f : 'a -> ('c -> 'd) -> 'c -> 'd)
in
eval_list inputs cf
-(** Unit test/example for [fold_left_apply_continuation] *)
+(** Unit test/example for {!fold_left_apply_continuation} *)
let _ =
fold_left_apply_continuation
(fun x cf (ctx : int) -> cf (ctx + x))
@@ -109,8 +109,8 @@ let _ =
(fun (ctx : int) -> assert (ctx = 4321))
0
-(** If we have a list of [inputs] of type `'a list` and a function [f] which
- evaluates one element of type `'a` to compute a result of type `'b` before
+(** If we have a list of [inputs] of type ['a list] and a function [f] which
+ evaluates one element of type ['a] to compute a result of type ['b] before
giving it to a continuation, the following function performs a fold operation:
it evaluates all the inputs one by one by accumulating the results in a list,
and gives the list to a continuation.
@@ -133,7 +133,7 @@ let fold_left_list_apply_continuation (f : 'a -> ('b -> 'c -> 'd) -> 'c -> 'd)
in
eval_list inputs cf []
-(** Unit test/example for [fold_left_list_apply_continuation] *)
+(** Unit test/example for {!fold_left_list_apply_continuation} *)
let _ =
fold_left_list_apply_continuation
(fun x cf (ctx : unit) -> cf (10 + x) ctx)
@@ -144,23 +144,23 @@ let _ =
(** Composition of functions taking continuations as parameters.
We sometimes have the following situation, where we want to compose three
- functions `send`, `transmit` and `receive` such that:
+ functions [send], [transmit] and [receive] such that:
- those three functions take continuations as parameters
- - `send` generates a value and gives it to its continuation
- - `receive` expects a value (so we can compose `send` and `receive` like
- so: `comp send receive`)
- - `transmit` doesn't expect any value and needs to be called between `send`
- and `receive`
+ - [send] generates a value and gives it to its continuation
+ - [receive] expects a value (so we can compose [send] and [receive] like
+ so: [comp send receive])
+ - [transmit] doesn't expect any value and needs to be called between [send]
+ and [receive]
- In this situation, we need to take the value given by `send` and "transmit"
- it to `receive`.
+ In this situation, we need to take the value given by [send] and "transmit"
+ it to [receive].
This is what this function does (see the unit test below for an illustration).
*)
let comp_transmit (f : ('v -> 'm) -> 'n) (g : 'm -> 'm) : ('v -> 'm) -> 'n =
fun cf -> f (fun v -> g (cf v))
-(** Example of use of [comp_transmit] *)
+(** Example of use of {!comp_transmit} *)
let () =
let return3 (cf : int -> unit -> unit) (ctx : unit) = cf 3 ctx in
let do_nothing (cf : unit -> unit) (ctx : unit) = cf ctx in
@@ -182,7 +182,7 @@ let comp_check_value (f : ('v -> 'ctx -> 'a) -> 'ctx -> 'b)
g v ctx;
cf v ctx)
-(** This case is similar to [comp_check_value], but even simpler (we only check
+(** This case is similar to {!comp_check_value}, but even simpler (we only check
the context)
*)
let comp_check_ctx (f : ('ctx -> 'a) -> 'ctx -> 'b) (g : 'ctx -> unit) :