I found an example of shift-reset delimited continuations in Haskell here:
resetT $ do alfa bravo x <- shiftT $ \esc -> do charlie lift $ esc 1 delta lift $ esc 2 return 0 zulu xThis will:
Perform
alfaPerform
bravoPerform
charlieBind
xto 1, and thus performzulu 1Fall off the end of
resetT, and jump back to just afteresc 1Perform
deltaBind
xto 2, and thus performzulu 2Fall off the end of
resetT, and jump back to just afteresc 2Escape from the
resetT, causing it to yield 0
I can't figure out how to write the equivalent code using SWI-Prolog's shift/1 and reset/3.
The code below is my attempt. The output is the same, but it seems messy and backwards, and I feel like I'm misusing Ball to get something similar to the esc 1 and esc 2 in the Haskell example. Also, I am not sure what to do with return 0.
% not sure about this...
example :-
reset(step, ball(X), Cont),
( writeln("charlie"), X=1, call(Cont), fail
; writeln("delta"), X=2, call(Cont)).
step :-
writeln("alfa"),
writeln("bravo"),
shift(ball(X)),
format("zulu ~w~n", X).
I'm rather confused: Scheme/Haskell/ML-style shift-reset and Prolog shift-reset seem almost like entirely different things! For example, you pass a lambda into Haskell's shiftT but you do not pass a goal into Prolog's shift/1.
Where is the Prolog equivalent of Haskell's \esc -> ... esc 1 or return 0? And where is the Haskell equivalent of Prolog's Ball or call(Cont)?
I feel that a "proper" port of the Haskell example above would answer these questions.