Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 119 lines (99 sloc) 3.028 kb
fccc685 Initial open-source release
MLstate authored
1 /*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 */
62c92c3 [doc] review: Review of stdlib.core
Guillem Rieu authored
18
fccc685 Initial open-source release
MLstate authored
19 /**
20 * Defining API on external continuation.
21 *
22 * This file provides the definition of a continuation, and define
23 * an API to manipulate them.
24 *
25 * @category general
26 * @author Mathieu Barbin, 2010
27 * @destination public
28 * @stability wip, unstable
29 */
30
31
32 /**
33 * {1 About this module}
34 *
35 * With the apparition of {[ @callcc : ( continuation('a) -> void ) : void }
36 * there is a need for the user to apply a continuation to a value of type ['a]
37 *
38 * Since the continuation will also be the native support of transactions,
39 * there is a need for an API.
62c92c3 [doc] review: Review of stdlib.core
Guillem Rieu authored
40 *
41 * {1 Where should I start?}
42 *
43 * {1 What if I need more?}
fccc685 Initial open-source release
MLstate authored
44 **/
45
46 /**
47 * {1 Types defined in this module}
48 **/
49
50 type bycps__unit = external
51
52 /**
53 * The abstract type of a continuation
54 */
55 @opacapi
56 type continuation('a) = external
57
62c92c3 [doc] review: Review of stdlib.core
Guillem Rieu authored
58 /**
59 * {1 Interface}
60 */
61
fccc685 Initial open-source release
MLstate authored
62 Continuation = {{
63
64 /**
65 * Return a value using a continuation : apply the continuation to the value.
66 * This is the standard function to use when you use @callcc
67 *
68 * {[
69 * f(x) =
70 * call(k) = Continuation.return(k, x)
71 * @callcc(call)
72 * }
73 *
74 * Do not use {!Continuation.execute} in standard cases.
75 **/
76 return = %%bslcps.user_return%% : continuation('a), 'a -> void
77
78 /**
79 * Like {!Continuation.return} but can't be scheduled before to return the value
80 * Hack for synchronous situations.
81 * Not for casual user.
82 **/
83 execute = %%bslcps.execute%% : continuation('a), 'a -> void
84
85 make = @may_cps(%%bslcps.user_cont%%) : ('a -> void) -> continuation('a)
86
87 /**
88 * This bypass is defined on both sides, but the client implementation is dummy.
89 * This is done so that the code may not be sliced differently if we add some debug
90 * print of the stack trace in the middle of a client-side code.
91 **/
92 print_trace_of = %% bslcps.print_trace %% : continuation('a) -> void
93
94 /**
95 * see {!Continuation.print_trace_of}
96 * applied on the current continuation.
97 **/
98 print_trace() : void =
99 @sliced_expr({
100 server =
101 @callcc(k ->
102 do print_trace_of(k)
103 return(k,void)
104 )
105 client =
106 error("Continuation.print_trace was called on the client side")
107 })
108 }}
109
110
111 /**
112 * The type of a future.
113 * Currently, used by generated code only.
114 * May become used by the user, if we export the
62c92c3 [doc] review: Review of stdlib.core
Guillem Rieu authored
115 * concurrency primitives spawn, wait.
fccc685 Initial open-source release
MLstate authored
116 **/
117 @opacapi
118 type Cps.future('a) = external
Something went wrong with that request. Please try again.