
Hi. I was curious if Haskell has something like "restarts" in Common Lisp. My search engines didn't give relevant results for "Haskell restarts". However, there were several results for "Haskell coroutines" and, from what I can gather, restarts and coroutines are a similar or related subject. -- http://www.lugod.org/presentations/pgp/why.html

How about the Control.Retry module in the 'retry' package? http://hackage.haskell.org/package/retry On Feb 11, 2014 12:51 AM, "Christopher Howard" < christopher.howard@frigidcode.com> wrote:
Hi. I was curious if Haskell has something like "restarts" in Common Lisp. My search engines didn't give relevant results for "Haskell restarts". However, there were several results for "Haskell coroutines" and, from what I can gather, restarts and coroutines are a similar or related subject.
-- http://www.lugod.org/presentations/pgp/why.html
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Or Control.Exception in the base package?
On Wed, 12 Feb 2014 19:16:39 +0100, Erik Dominikus
How about the Control.Retry module in the 'retry' package?
http://hackage.haskell.org/package/retry On Feb 11, 2014 12:51 AM, "Christopher Howard" < christopher.howard@frigidcode.com> wrote:
Hi. I was curious if Haskell has something like "restarts" in Common Lisp. My search engines didn't give relevant results for "Haskell restarts". However, there were several results for "Haskell coroutines" and, from what I can gather, restarts and coroutines are a similar or related subject.
Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

"Henk-Jan van Tuyl"
Or Control.Exception in the base package?
With Lisp-style restarts, exceptions (Common Lisp calls them "conditions") don't necessarily "unwind the stack." Instead, they provide a set of alternatives for how to proceed. Calls to the throwing function can be wrapped in a handler that chooses, say, whether to skip or abort. To take a Haskell example, Data.Text.Encoding has an API for doing Unicode decoding with "controllable error handling." It's pretty simple, and not very flexible.
type OnDecodeError = String -> Maybe Word8 -> Maybe Char
decodeUtf8With :: OnDecodeError -> ByteString -> Text
Considering some different possibilities for this API... Something like this (a kind of defunctionalized version) might be more familiar to a CL programmer:
data DecodeCondition = InvalidWord Word8 | UnexpectedEOF data DecodeRestart = Ignore | UseChar Char
decodeUtf8With :: (DecodeCondition -> DecodeRestart) -> ByteString -> Text
We can use ImplicitParams to approximate the dynamic scope behavior, and LambdaCase to write what CL calls the "restart-case":
decodeUtf8 :: (?restart :: DecodeCondition -> DecodeRestart) -> ByteString -> Text
Usage:
myDecode s = let ?restart = \case InvalidWord _ -> UseChar '*' UnexpectedEOF -> Ignore in decodeUtf8 s
* * * One of the cool things about CL's condition system that this implementation doesn't capture is the way the runtime environment can provide interactive prompts for restarting uncaught conditions. An example session:
CL-USER 6 > (restartable-gethash 'mango *fruits-and-vegetables*)
Error: RESTARTABLE-GETHASH error getting MANGO [...] 1 (continue) Return not having found the value. 2 Try getting the key from the hash again. 3 Use a new key. 4 Use a new hash. 5 (abort) Return to level 0. 6 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other options
To increase the flexibility of our purely functional restarts, we can use monads:
decodeUtf8With :: Monad m => (DecodeCondition -> m DecodeRestart) -> ByteString -> m Text
myDecode :: ByteString -> IO Text myDecode = decodeUtf8With (\c -> askUserAbout c >>= decide)
We can also use other monads:
cautiousDecode :: ByteString -> Maybe Text cautiousDecode = decodeUtf8With (const Nothing)
This of course opens up a whole world of bizarre control flow possibilities. -- Mikael Brockman @mbrock

On Tue, Feb 11, 2014 at 12:33 AM, Christopher Howard < christopher.howard@frigidcode.com> wrote:
I was curious if Haskell has something like "restarts" in Common Lisp. My search engines didn't give relevant results for "Haskell restarts".
Searching "lisp style restarts" brings up this Haskell-relevant link: http://lambda-the-ultimate.org/node/1544 -- Kim-Ee
participants (5)
-
Christopher Howard
-
Erik Dominikus
-
Henk-Jan van Tuyl
-
Kim-Ee Yeoh
-
Mikael Brockman