haskell / haskell/primitive

PrimUnlifted class

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

Description

I'd like to move this from `primitive-unlifted` into this `primitive`:

```
class PrimUnlifted a where
type Unlifted a :: UnliftedType
toUnlifted# :: a -> Unlifted a
fromUnlifted# :: Unlifted a -> a

instance PrimUnlifted (Array a) where
type Unlifted (Array a) = Array# a
toUnlifted# (Array a) = a
fromUnlifted# x = Array x

instance PrimUnlifted (MutableArray s a) where
type Unlifted (MutableArray s a) = MutableArray# s a
toUnlifted# (MutableArray a) = a
fromUnlifted# x = MutableArray x

instance PrimUnlifted (SmallArray a) where
type Unlifted (SmallArray a) = SmallArray# a
toUnlifted# (SmallArray a) = a
fromUnlifted# x = SmallArray x

instance PrimUnlifted (SmallMutableArray s a) where
type Unlifted (SmallMutableArray s a) = SmallMutableArray# s a
toUnlifted# (SmallMutableArray a) = a
fromUnlifted# x = SmallMutableArray x

instance PrimUnlifted (PrimArray a) where
type Unlifted (PrimArray a) = ByteArray#
toUnlifted# (PrimArray x) = x
fromUnlifted# x = PrimArray x

instance PrimUnlifted ByteArray where
type Unlifted ByteArray = ByteArray#
toUnlifted# (ByteArray x) = x
fromUnlifted# x = ByteArray x
```

I'd have to give up on the `ShortText` and `ShortByteString` instances since `primitive` is not going to pick up `bytestring` or `text-short` as a dependency. Having this typeclass would let us have a much more useful implementation of `touch` and `keepAlive`. Any implementation of these targeting a lifted wrapper is dangerous and misleading to the user. Unfortunately, that's basically the *only* thing we would get from doing this. All the other stuff using this class needs to stay in `primitive-unlifted` for at least a while longer since the backwards-compatibility story for it is rather bad. I do think that `PrimUnlifted` is stable at this point though.

Any thoughts on this?

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.