Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PrimUnlifted class #379

Open
andrewthad opened this issue Mar 23, 2023 · 4 comments
Open

PrimUnlifted class #379

andrewthad opened this issue Mar 23, 2023 · 4 comments

Comments

@andrewthad
Copy link
Collaborator

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?

@konsumlamm
Copy link
Contributor

I assume we'd also want instances for MutablePrimArray and MutableByteArray?

@andrewthad
Copy link
Collaborator Author

Yes, those as well. And MutVar. We cannot do PrimVar at the moment though because we would want it to lower to an unlifted newtype PrimVar#, which cannot exist in GHCs before 8.10.

@treeowl
Copy link
Collaborator

treeowl commented Mar 23, 2023

It sounds to me like delaying this would be better, and just adding adequate documentation in primitive to point over. There just isn't enough benefit yet.

@chessai
Copy link
Member

chessai commented Sep 29, 2023

It sounds to me like delaying this would be better, and just adding adequate documentation in primitive to point over. There just isn't enough benefit yet.

Do you specifically mean delaying until we drop GHC 8.10?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants