Conversion between STRef RealWorld and IORef

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Conversion between STRef RealWorld and IORef

Wolfgang Jeltsch-2
Hi,

I need to convert values of types STRef RealWorld a to IORef a in order
to attach finalizers to them. For now, I am using GHC.IORef for this. Is
there a better way to achieve what I want?

All the best,
Wolfgang

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Conversion between STRef RealWorld and IORef

John Lato-2
Really a function like mkWeakIORef should be exposed for STRef's. I know there's supposed to be a patch to normalize various weak'ish things (ekmett?), maybe that function could be added at the same time.

Until then, I would suggesy unpacking the STRef to get at the underlying MutVar#, and copy the IORef code (which IIRC also works on MutVar#) to write the function yourself.

John L.

On 07:56, Mon, Dec 1, 2014 Wolfgang Jeltsch <[hidden email]> wrote:
Hi,

I need to convert values of types STRef RealWorld a to IORef a in order
to attach finalizers to them. For now, I am using GHC.IORef for this. Is
there a better way to achieve what I want?

All the best,
Wolfgang

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Conversion between STRef RealWorld and IORef

Wolfgang Jeltsch-2
Hi,

my STRefs have the RealWorld parameter. For now, I do not unpack the
STRefs, but wrap them with the IORef constructor and use mkWeakIORef on
the resulting IORef. I guess this should be sane. Is there any reason
why this should not work?

All the best,
Wolfgang

Am Montag, den 01.12.2014, 21:21 +0000 schrieb John Lato:

> Really a function like mkWeakIORef should be exposed for STRef's. I
> know there's supposed to be a patch to normalize various weak'ish
> things (ekmett?), maybe that function could be added at the same
> time.
>
> Until then, I would suggesy unpacking the STRef to get at the
> underlying MutVar#, and copy the IORef code (which IIRC also works on
> MutVar#) to write the function yourself.
>
> John L.
>
> On 07:56, Mon, Dec 1, 2014 Wolfgang Jeltsch
> <[hidden email]> wrote:
>         Hi,
>        
>         I need to convert values of types STRef RealWorld a to IORef a
>         in order
>         to attach finalizers to them. For now, I am using GHC.IORef
>         for this. Is
>         there a better way to achieve what I want?
>        
>         All the best,
>         Wolfgang
>        
>         _______________________________________________
>         Libraries mailing list
>         [hidden email]
>         http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Conversion between STRef RealWorld and IORef

John Lato-2
AFAIUI wrapping in an IORef constructor then calling mkWeakIORef simply to add a finalizer should be fine.

On Tue Dec 02 2014 at 5:12:24 AM Wolfgang Jeltsch <[hidden email]> wrote:
Hi,

my STRefs have the RealWorld parameter. For now, I do not unpack the
STRefs, but wrap them with the IORef constructor and use mkWeakIORef on
the resulting IORef. I guess this should be sane. Is there any reason
why this should not work?

All the best,
Wolfgang

Am Montag, den 01.12.2014, 21:21 +0000 schrieb John Lato:
> Really a function like mkWeakIORef should be exposed for STRef's. I
> know there's supposed to be a patch to normalize various weak'ish
> things (ekmett?), maybe that function could be added at the same
> time.
>
> Until then, I would suggesy unpacking the STRef to get at the
> underlying MutVar#, and copy the IORef code (which IIRC also works on
> MutVar#) to write the function yourself.
>
> John L.
>
> On 07:56, Mon, Dec 1, 2014 Wolfgang Jeltsch
> <[hidden email]> wrote:
>         Hi,
>
>         I need to convert values of types STRef RealWorld a to IORef a
>         in order
>         to attach finalizers to them. For now, I am using GHC.IORef
>         for this. Is
>         there a better way to achieve what I want?
>
>         All the best,
>         Wolfgang
>
>         _______________________________________________
>         Libraries mailing list
>         [hidden email]
>         http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries

_______________________________________________
Libraries mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/libraries