[Haskell-cafe] using Typeable with STRefs

2009-03-16 Thread Michael Vanier
Hi, I'm having a problem using Typeable with STRefs. Basically, I want to store STRefs (among other things) in a universal type. STRef is an instance of Typeable2, which means that STRef s a is Typeable if s and a are both Typeable. The problem is that the state type s is opaque and I can

Re: [Haskell-cafe] using Typeable with STRefs

2009-03-16 Thread Ryan Ingram
Having the state be an instance of Typeable breaks the purity guarantees of runST; a reference could escape runST: let v = runST (V `liftM` newSTRef 0) in runST (readSTRef $ fromJust $ getValue v) Keep in mind that the state actually used by runST is RealWorld; runST is just a pretty name

Re: [Haskell-cafe] using Typeable with STRefs

2009-03-16 Thread Michael Vanier
Ryan, So, if I understand you correctly, my only option is to use an IORef instead of an STRef? What I'm trying to do is implement a mutable box type as part of a dynamically-typed language I'm implementing in Haskell (which is mainly an exercise to improve my Haskell programming; mission

Re: [Haskell-cafe] using Typeable with STRefs

2009-03-16 Thread Antoine Latter
On Mon, Mar 16, 2009 at 8:08 PM, Michael Vanier mvanie...@gmail.com wrote: Ryan, So, if I understand you correctly, my only option is to use an IORef instead of an STRef?  What I'm trying to do is implement a mutable box type as part of a dynamically-typed language I'm implementing in Haskell

Re: [Haskell-cafe] using Typeable with STRefs

2009-03-16 Thread Antoine Latter
Why not: data Value = forall a . Typeable a = V a type STValue s = STRef Value This should be: type STValue s = STRef s Value Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe