The Continuation Monad¶
-
class
hymn.types.continuation.
Continuation
(value)¶ Bases:
hymn.types.monad.Monad
the continuation monad
-
bind
(f)¶ the bind operation of
Continuation
-
run
(k=<function identity>)¶ run the continuation
-
classmethod
unit
(value)¶ the unit of continuation monad
-
-
hymn.types.continuation.
call_cc
(f)¶ call with current continuation
-
hymn.types.continuation.
cont_m
¶ alias of
Continuation
-
hymn.types.continuation.
continuation_m
¶ alias of
Continuation
-
hymn.types.continuation.
unit
()¶ alias of
Continuation.unit()
-
hymn.types.continuation.
run
()¶ alias of
Continuation.run()
Hy Specific API¶
-
cont-m
-
continuation-m
alias of
Continuation
Tag Macro¶
-
< [v]
create a
Continuation
ofv
Examples¶
Do Notation¶
=> (import [hymn.types.continuation [cont-m]])
=> (require [hymn.macros [do-monad]])
=> (.run (do-monad [a (cont-m.unit 1)] (inc a)))
2
Operations¶
call-cc()
- call with current continuation
=> (import [hymn.types.continuation [call-cc cont-m]])
=> (require [hymn.macros [m-when do-monad-with]])
=> (defn search [n seq]
... (call-cc
... (fn [exit]
... (do-monad-with cont-m
... [_ (m-when (in n seq) (exit (.index seq n)))]
... "not found."))))
=> (.run (search 0 [1 2 3 4 5]))
'not found.'
=> (.run (search 0 [1 2 3 0 5]))
3
Tag Macro¶
=> (require [hymn.types.continuation [<]])
=> (#< 42)
42
=> (require [hymn.macros [do-monad]])
=> (.run (do-monad [a #< 25 b #< 17] (+ a b)))
42