
Hi haskell cafe:
concerning Stable Names
http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-Stable...
makeStableName :: a -> IO (StableName a)
I Did not test fully my proposal, and I´m thinking aloud, Just to inpire
others and fish some ideas;
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 :: a -> Transient (StableName a)
The key here is to maintain the programmer aware that it is not pure, but
there are no IO and that the results have no meaning from session to
session.
Instance Monad Transient where
Transient x ↠ f = f x
return x = Transient x
We can Transient`ize IO calls by means of an implicit memoization:
liftT:: IO a -> Transient a
liftT= < whatever memoization code>
liftT2=....
liftT3=....
Memorization then is embedded in the monad transformation
This may be more elegant than IO plus unsafePerformIO and is more
informative for the programmer. The transition form IO to pure can be done
in two steps, see below
Instead of unsafePerformIO, we can use:
unsafePurifyTransient :: Transient a -> a
unsafePurifyTransient (Transient x) = x
for the inherently transient calls
A safer version of unsafePerformIO using implicit memoization could be:
unsafePerformIOT :: IO a -> a
unsafePerformIOT = unsafePurifyTransient . liftT
unsafePerformIOT guatantee that it returns the same value in the same
session.
2009/12/8 Vladimir Zlatanov
wrote: I think lisp like symbols could be quite useful in the context of embedded DSL to create ... well... symbols that can be interpreted as variables in that DSL.
Well for such use-case you could use either stable names, or recode them into a state monad- you will get either a global i.e. lisp like unique symbols, or their equivalent within a state context. Or some variation of the code posted previously in this thread.
http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-Stable... _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

+1 Alberto G. Corona wrote:
Hi haskell cafe:
concerning Stable Names
http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-Stable...
makeStableName :: a -> IO (StableName a)
I Did not test fully my proposal, and I´m thinking aloud, Just to inpire others and fish some ideas;
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 :: a -> Transient (StableName a)
The key here is to maintain the programmer aware that it is not pure, but there are no IO and that the results have no meaning from session to session.
Instance Monad Transient where Transient x ↠ f = f x return x = Transient x
We can Transient`ize IO calls by means of an implicit memoization:
liftT:: IO a -> Transient a liftT= < whatever memoization code> liftT2=.... liftT3=....
Memorization then is embedded in the monad transformation This may be more elegant than IO plus unsafePerformIO and is more informative for the programmer. The transition form IO to pure can be done in two steps, see below
Instead of unsafePerformIO, we can use:
unsafePurifyTransient :: Transient a -> a unsafePurifyTransient (Transient x) = x
for the inherently transient calls
A safer version of unsafePerformIO using implicit memoization could be: unsafePerformIOT :: IO a -> a unsafePerformIOT = unsafePurifyTransient . liftT
unsafePerformIOT guatantee that it returns the same value in the same session.
2009/12/8 Vladimir Zlatanov
wrote: I think lisp like symbols could be quite useful in the context of embedded DSL to create ... well... symbols that can be interpreted as variables in that DSL.
Well for such use-case you could use either stable names, or recode them into a state monad- you will get either a global i.e. lisp like unique symbols, or their equivalent within a state context. Or some variation of the code posted previously in this thread.

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
participants (3)
-
Alberto G. Corona
-
Ben Franksen
-
Twan van Laarhoven