haskell / haskell/primitive

Add support for weak references with unlifted keys

Open
#210 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
123
Forks
60
PR merge metrics
No merged PRs in 30d

Description

We should be able to write

```haskell
mkWeakFromUnlifted
:: (PrimUnlifted k, PrimMonad m, PrimState m ~ RealWorld)
=> k -> v -> IO () -> m (Weak v)
```

We should also be able to write a (nasty) type

```haskell
newtype WeakUnlifted a =
WeakUnlifted (Weak Any)
type role WeakUnlifted representational
```

This would allow weak references *containing* unlifted values. The GHC primops language doesn't seem to know how to express such a primitive type yet, although it's conceptually simple. We'd end up with four fundamental creation functions.

Relatedly, we should offer

```haskell
touchUnlifted
:: (PrimUnlifted a, PrimMonad m, PrimState m ~ RealWorld)
=> a -> m ()
touchUnlifted a =
primitive_ $ touch# (toUnlifted# a)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.