[Haskell-cafe] The Transient monad

Twan van Laarhoven twanvl at gmail.com
Tue Dec 8 17:05:04 EST 2009

Alberto G. Corona wrote:
> Hi haskell cafe:
> concerning Stable Names 
> The IO in makeStableName  suggest more side effects than makeStableName 
> really do. But still the call isn't pure.
> For calls such are makeStableName that gives a different result the 
> FIRST time they are called but return the same result every time in the 
> same session,  I suggest to use a Transient monad:

makeStableName doesn't really give 'the same result every time', though. For 

     *> let sn x = hashStableName <$> makeStableName x
     *> let x = replicate 3 'x' in (,) <$> sn x <* evaluate x <*> sn x

After x is evaluated in this example, its stable name changes.

Perhaps instead of Transient we could use a name that makes it more clear what 
is going on, perhaps "ObservingEvaluation". That could also include exception 
handling, by the way.

> makeStableName :: a -> Transient (StableName a)

Why not wrap it up in a class?

     class Monad m => MonadObservingEvaluation m where
         -- what should go here? perhaps:
         liftOE :: ObservingEvaluation a -> m a

Then we can have

     makeStableName :: MonadObservingEvaluation m => a -> m (StableName a)

Which works both in IO and the new monad.


More information about the Haskell-Cafe mailing list