Monadic Call/CC?

Ashley Yakeley ashley@semantic.org
Thu, 21 Feb 2002 01:18:05 -0800


At 2002-02-20 22:15, I wrote (on the Haskell list):

>Haskell? Given this:
>
>    class (Monad m) => PeirceMonad m where
>	      	{
>	      	peirceM :: ((a -> m b) -> m a) -> m a;
>	      	};
>
>...which Monads can be made PeirceMonads?

This is untested, but...

    instance PeirceMonad IO where
        {
        peirceM foo = do
            {
            ref <- newIORef Nothing;
            catch (foo (\a -> do
                {
                writeIORef ref (Just a);
                ioError (userError "break");
                }))
                (\ex -> do
                {
                ma <- readIORef ref;
                case ma of
                    {
                    Just a -> return a;
                    _ -> ioError ex;
                    };
                })
            }
        };

So you can do it if you have refs and throw/catch for your monad. I think.


-- 
Ashley Yakeley, Seattle WA