Skip to content

PrimUnlifted class #379

Open
Open
@andrewthad

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?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions