Ticket #1169: Control-Monad-Cont-Class.html

File Control-Monad-Cont-Class.html, 10.0 KB (added by guest, 7 years ago)

Version 4 of the Haddock output

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<!--Rendered using the Haskell Html Library v0.2-->
3<HTML
4><HEAD
5><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"
6><TITLE
7>Control.Monad.Cont.Class</TITLE
8>
9
10<style TYPE="text/css">
11/* -------- Global things --------- */
12
13BODY { 
14  background-color: #ffffff;
15  color: #000000;
16  font-family: sans-serif;
17  } 
18
19A:link    { color: #0000e0; text-decoration: none }
20A:visited { color: #0000a0; text-decoration: none }
21A:hover   { background-color: #e0e0ff; text-decoration: none }
22
23TABLE.vanilla {
24  width: 100%;
25  border-width: 0px;
26  /* I can't seem to specify cellspacing or cellpadding properly using CSS... */
27}
28
29TABLE.vanilla2 {
30  border-width: 0px;
31}
32
33/* <TT> font is a little too small in MSIE */
34TT  { font-size: 100%; }
35PRE { font-size: 100%; }
36
37LI P { margin: 0pt } 
38
39TD {
40  border-width: 0px;
41}
42
43TABLE.narrow {
44  border-width: 0px;
45}
46
47TD.s8  {  height: 8px;  }
48TD.s15 {  height: 15px; }
49
50SPAN.keyword { text-decoration: underline; }
51
52/* Resize the buttom image to match the text size */
53IMG.coll { width : 0.75em; height: 0.75em; margin-bottom: 0; margin-right: 0.5em }
54
55/* --------- Contents page ---------- */
56
57DIV.node {
58  padding-left: 3em;
59}
60
61DIV.cnode {
62  padding-left: 1.75em;
63}
64
65SPAN.pkg {
66  position: absolute;
67  left: 50em;
68}
69
70/* --------- Documentation elements ---------- */
71
72TD.children {
73  padding-left: 25px;
74  }
75
76TD.synopsis {
77  padding: 2px;
78  background-color: #f0f0f0;
79  font-family: monospace
80 }
81
82TD.decl { 
83  padding: 2px;
84  background-color: #f0f0f0; 
85  font-family: monospace;
86  vertical-align: top;
87  }
88
89/*
90  arg is just like decl, except that wrapping is not allowed.  It is
91  used for function and constructor arguments which have a text box
92  to the right, where if wrapping is allowed the text box squashes up
93  the declaration by wrapping it.
94*/
95TD.arg { 
96  padding: 2px;
97  background-color: #f0f0f0; 
98  font-family: monospace;
99  vertical-align: top;
100  white-space: nowrap;
101  }
102
103TD.recfield { padding-left: 20px }
104
105TD.doc  { 
106  padding-top: 2px;
107  padding-left: 10px;
108  }
109
110TD.ndoc  { 
111  padding: 2px;
112  }
113
114TD.rdoc  { 
115  padding: 2px;
116  padding-left: 10px;
117  width: 100%;
118  }
119
120TD.body  { 
121  padding-left: 10px
122  }
123
124TD.pkg {
125  width: 100%;
126  padding-left: 10px
127}
128
129TD.indexentry {
130  vertical-align: top;
131  padding-right: 10px
132  }
133
134TD.indexannot {
135  vertical-align: top;
136  padding-left: 20px;
137  white-space: nowrap
138  }
139
140TD.indexlinks {
141  width: 100%
142  }
143
144/* ------- Section Headings ------- */
145
146TD.section1 {
147  padding-top: 15px;
148  font-weight: bold;
149  font-size: 150%
150  }
151
152TD.section2 {
153  padding-top: 10px;
154  font-weight: bold;
155  font-size: 130%
156  }
157
158TD.section3 {
159  padding-top: 5px;
160  font-weight: bold;
161  font-size: 110%
162  }
163
164TD.section4 {
165  font-weight: bold;
166  font-size: 100%
167  }
168
169/* -------------- The title bar at the top of the page */
170
171TD.infohead {
172  color: #ffffff;
173  font-weight: bold;
174  padding-right: 10px;
175  text-align: left;
176}
177
178TD.infoval {
179  color: #ffffff;
180  padding-right: 10px;
181  text-align: left;
182}
183
184TD.topbar {
185  background-color: #000099;
186  padding: 5px;
187}
188
189TD.title {
190  color: #ffffff;
191  padding-left: 10px;
192  width: 100%
193  }
194
195TD.topbut {
196  padding-left: 5px;
197  padding-right: 5px;
198  border-left-width: 1px;
199  border-left-color: #ffffff;
200  border-left-style: solid;
201  white-space: nowrap;
202  }
203
204TD.topbut A:link {
205  color: #ffffff
206  }
207
208TD.topbut A:visited {
209  color: #ffff00
210  }
211
212TD.topbut A:hover {
213  background-color: #6060ff;
214  }
215
216TD.topbut:hover {
217  background-color: #6060ff
218  }
219
220TD.modulebar { 
221  background-color: #0077dd;
222  padding: 5px;
223  border-top-width: 1px;
224  border-top-color: #ffffff;
225  border-top-style: solid;
226  }
227
228/* --------- The page footer --------- */
229
230TD.botbar {
231  background-color: #000099;
232  color: #ffffff;
233  padding: 5px
234  }
235TD.botbar A:link {
236  color: #ffffff;
237  text-decoration: underline
238  }
239TD.botbar A:visited {
240  color: #ffff00
241  }
242TD.botbar A:hover {
243  background-color: #6060ff
244  }
245</style>
246
247<SCRIPT SRC="haddock.js" TYPE="text/javascript"
248></SCRIPT
249></HEAD
250><BODY
251><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
252><TR
253><TD CLASS="topbar"
254><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
255><TR
256><TD
257><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" "
258></TD
259><TD CLASS="title"
260></TD
261><TD CLASS="topbut"
262><A HREF="index.html"
263>Contents</A
264></TD
265><TD CLASS="topbut"
266><A HREF="doc-index.html"
267>Index</A
268></TD
269></TR
270></TABLE
271></TD
272></TR
273><TR
274><TD CLASS="modulebar"
275><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
276><TR
277><TD
278><FONT SIZE="6"
279>Control.Monad.Cont.Class</FONT
280></TD
281><TD ALIGN="right"
282><TABLE CLASS="narrow" CELLSPACING="0" CELLPADDING="0"
283><TR
284><TD CLASS="infohead"
285>Portability</TD
286><TD CLASS="infoval"
287>non-portable (multi-parameter type classes)</TD
288></TR
289><TR
290><TD CLASS="infohead"
291>Stability</TD
292><TD CLASS="infoval"
293>experimental</TD
294></TR
295><TR
296><TD CLASS="infohead"
297>Maintainer</TD
298><TD CLASS="infoval"
299>libraries@haskell.org</TD
300></TR
301></TABLE
302></TD
303></TR
304></TABLE
305></TD
306></TR
307><TR
308><TD CLASS="s15"
309></TD
310></TR
311><TR
312><TD
313><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
314></TABLE
315></TD
316></TR
317><TR
318><TD CLASS="s15"
319></TD
320></TR
321><TR
322><TD CLASS="section1"
323>Description</TD
324></TR
325><TR
326><TD CLASS="doc"
327><DL
328><DT
329>Computation type:</DT
330><DD
331> Computations which can be interrupted and resumed.
332</DD
333><DT
334>Binding strategy:</DT
335><DD
336> Binding a function to a monadic value creates
337a new continuation which uses the function as the continuation of the monadic
338computation.
339</DD
340><DT
341>Useful for:</DT
342><DD
343> Complex control structures, error handling,
344and creating co-routines.
345</DD
346><DT
347>Zero and plus:</DT
348><DD
349> None.
350</DD
351><DT
352>Example type:</DT
353><DD
354> <TT
355>Cont r a</TT
356>
357</DD
358></DL
359><P
360>The Continuation monad represents computations in continuation-passing style
361(CPS).
362In continuation-passing style function result is not returned,
363but instead is passed to another function,
364received as a parameter (continuation).
365Computations are built up from sequences
366of nested continuations, terminated by a final continuation (often <TT
367>id</TT
368>)
369which produces the final result.
370Since continuations are functions which represent the future of a computation,
371manipulation of the continuation functions can achieve complex manipulations
372of the future of the computation,
373such as interrupting a computation in the middle, aborting a portion
374of a computation, restarting a computation, and interleaving execution of
375computations.
376The Continuation monad adapts CPS to the structure of a monad.
377</P
378><P
379>Before using the Continuation monad, be sure that you have
380a firm understanding of continuation-passing style
381and that continuations represent the best solution to your particular
382design problem.
383Many algorithms which require continuations in other languages do not require
384them in Haskell, due to Haskell's lazy semantics.
385Abuse of the Continuation monad can produce code that is impossible
386to understand and maintain.
387</P
388></TD
389></TR
390><TR
391><TD CLASS="s15"
392></TD
393></TR
394><TR
395><TD CLASS="s15"
396></TD
397></TR
398><TR
399><TD CLASS="section1"
400>Documentation</TD
401></TR
402><TR
403><TD CLASS="s15"
404></TD
405></TR
406><TR
407><TD CLASS="decl"
408><SPAN CLASS="keyword"
409>class</SPAN
410> Monad m =&gt; <A NAME="t%3AMonadCont"
411></A
412><B
413>MonadCont</B
414> m  <SPAN CLASS="keyword"
415>where</SPAN
416></TD
417></TR
418><TR
419><TD CLASS="body"
420><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
421><TR
422><TD CLASS="s8"
423></TD
424></TR
425><TR
426><TD CLASS="section4"
427>Methods</TD
428></TR
429><TR
430><TD CLASS="body"
431><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
432><TR
433><TD CLASS="decl"
434><A NAME="v%3AcallCC"
435></A
436><B
437>callCC</B
438> :: ((a -&gt; m b) -&gt; m a) -&gt; m a</TD
439></TR
440><TR
441><TD CLASS="doc"
442><P
443><TT
444>callCC</TT
445> (call-with-current-continuation)
446    calls a function with the current continuation as its argument.
447    Provides an escape continuation mechanism for use with Continuation monads.
448    Escape continuations allow to abort the current computation and return
449    a value immediately.
450    They achieve a similar effect to <TT
451><A HREF="Control-Monad-Error.html#v%3AthrowError"
452>throwError</A
453></TT
454>
455    and <TT
456><A HREF="Control-Monad-Error.html#v%3AcatchError"
457>catchError</A
458></TT
459>
460    within an <TT
461><A HREF="Control-Monad-Error.html#t%3AError"
462>Error</A
463></TT
464> monad.
465    Advantage of this function over calling <TT
466>return</TT
467> is that it makes
468    the continuation explicit,
469    allowing more flexibility and better control
470    (see examples in <A HREF="Control-Monad-Cont.html"
471>Control.Monad.Cont</A
472>).
473</P
474><P
475>The standard idiom used with <TT
476>callCC</TT
477> is to provide a lambda-expression
478    to name the continuation. Then calling the named continuation anywhere
479    within its scope will escape from the computation,
480    even if it is many layers deep within nested computations.
481</P
482></TD
483></TR
484></TABLE
485></TD
486></TR
487><TR
488><TD CLASS="s8"
489></TD
490></TR
491><TR
492><TD CLASS="section4"
493><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:MonadCont')" ALT="show/hide"
494> Instances</TD
495></TR
496><TR
497><TD CLASS="body"
498><DIV ID="i:MonadCont" STYLE="display:block;"
499><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
500><TR
501><TD CLASS="decl"
502><A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
503>MonadCont</A
504> (<A HREF="Control-Monad-Cont.html#t%3ACont"
505>Cont</A
506> r)</TD
507></TR
508><TR
509><TD CLASS="decl"
510>Monad m =&gt; <A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
511>MonadCont</A
512> (<A HREF="Control-Monad-Cont.html#t%3AContT"
513>ContT</A
514> r m)</TD
515></TR
516><TR
517><TD CLASS="decl"
518>(<A HREF="Control-Monad-Error-Class.html#t%3AError"
519>Error</A
520> e, <A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
521>MonadCont</A
522> m) =&gt; <A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
523>MonadCont</A
524> (<A HREF="Control-Monad-Error.html#t%3AErrorT"
525>ErrorT</A
526> e m)</TD
527></TR
528><TR
529><TD CLASS="decl"
530><A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
531>MonadCont</A
532> m =&gt; <A HREF="Control-Monad-Cont-Class.html#t%3AMonadCont"
533>MonadCont</A
534> (<A HREF="Control-Monad-Reader.html#t%3AReaderT"
535>ReaderT</A
536> r m)</TD
537></TR
538></TABLE
539></DIV
540></TD
541></TR
542></TABLE
543></TD
544></TR
545><TR
546><TD CLASS="s15"
547></TD
548></TR
549><TR
550><TD CLASS="botbar"
551>Produced by <A HREF="http://www.haskell.org/haddock/"
552>Haddock</A
553> version 0.7</TD
554></TR
555></TABLE
556></BODY
557></HTML
558>