module Deep:sig
..end
深層處理器
type ('a, 'b)
continuation
('a,'b) continuation
是一個定界的續延,它期望一個 'a
值並回傳一個 'b
值。
val continue : ('a, 'b) continuation -> 'a -> 'b
continue k x
透過傳遞 x
給 k
來恢復續延 k
。
Continuation_already_resumed
異常。val discontinue : ('a, 'b) continuation -> exn -> 'b
discontinue k e
透過在 k
中引發異常 e
來恢復續延 k
。
Continuation_already_resumed
異常。val discontinue_with_backtrace : ('a, 'b) continuation ->
exn -> Printexc.raw_backtrace -> 'b
discontinue_with_backtrace k e bt
透過使用 bt
作為異常的來源,在 k
中引發異常 e
來恢復續延 k
。
Continuation_already_resumed
異常。type ('a, 'b)
handler = {
|
retc : |
|
exnc : |
|
effc : |
}
('a,'b) handler
是一個處理器記錄,包含三個欄位 -- retc
是數值處理器,exnc
處理例外,而 effc
處理被處理器封閉的計算所執行的效果。
val match_with : ('c -> 'a) -> 'c -> ('a, 'b) handler -> 'b
match_with f v h
在處理器 h
中執行計算 f v
。
type 'a
effect_handler = {
|
effc : |
}
'a effect_handler
是一個深層處理器,具有一個恆等數值處理器 fun x -> x
和一個會引發任何異常的例外處理器 fun e -> raise e
。
val try_with : ('b -> 'a) -> 'b -> 'a effect_handler -> 'a
try_with f v h
在處理器 h
下執行計算 f v
。
val get_callstack : ('a, 'b) continuation -> int -> Printexc.raw_backtrace
get_callstack c n
回傳續延 c
上的呼叫堆疊頂部的描述,最多包含 n
個項目。