The Continuation Monad¶
- class hymn.types.continuation.Continuation¶
the continuation monad
- bind(self, f)¶
the bind operation of
Continuation
- classmethod unit(cls, value)¶
the unit of continuation monad
- run(self, k=identity)¶
run the continuation
- hymn.types.continuation.call_cc(f)¶
call with current continuation
Hy Specific API¶
- cont-m
- continuation-m
alias of
Continuation
- call/cc
alias of
call_cc()
Reader Macro¶
- < [v]
create a
Continuation
ofv
Examples¶
Do Notation¶
=> (import hymn.types.continuation [cont-m])
=> (require hymn.macros [do-monad-return])
=> (.run (do-monad-return [a (cont-m.unit 1)] (+ a 1)))
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
Reader Macro¶
=> (require hymn.types.continuation :readers [<])
=> (#< 42)
42
=> (require hymn.macros [do-monad-return])
=> (.run (do-monad-return [a #< 25 b #< 17] (+ a b)))
42