
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 example: *> let sn x = hashStableName <$> makeStableName x *> let x = replicate 3 'x' in (,) <$> sn x <* evaluate x <*> sn x (18,17) 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. Twan