[Haskell-cafe] A curios monad

Martijn van Steenbergen martijn at van.steenbergen.nl
Fri Dec 12 16:57:33 EST 2008


Ryan Ingram wrote:
> Here's a simple example:
> 
> runMud :: Mud a -> a
> runMud = flip evalState emptyMud
> 
> main = do
>     let v = runMud (mkVar "hello")
>     let crash = runMud $ do
>         v2 <- mkVar True  -- v2 :: Var Bool
>         res <- readVar v -- v :: Var String
>         return res
>     print crash -- boom!
> 
> Both v2 and v are the same variable index (0), but different types.
> Since there's nothing preventing the variable from escaping from the
> first "runMud", we can import it into the second one where it fails.
> The key is that both use the same "initial state", so you have lost
> the uniqueness of variables.

Ah, yes, of course, thank you. :-) I was trying to break it from within 
the monad.

Martijn.



More information about the Haskell-Cafe mailing list