{-# language KindSignatures #-}
{-# language TypeFamilies #-}
{-# language MagicHash #-}

module Data.Primitive.Unlifted.Box where
import GHC.Exts (TYPE, RuntimeRep (UnliftedRep))
import Data.Primitive.Unlifted.Class

data Box (a :: TYPE 'UnliftedRep) = Box# { Box a -> a
unBox# :: a }

instance PrimUnlifted (Box a) where
  {-# INLINE toUnlifted# #-}
  {-# INLINE fromUnlifted# #-}
  type Unlifted (Box a) = a

  toUnlifted# :: Box a -> Unlifted (Box a)
toUnlifted# (Box# a
a) = a
Unlifted (Box a)
a
  fromUnlifted# :: Unlifted (Box a) -> Box a
fromUnlifted# Unlifted (Box a)
a = a -> Box a
forall (a :: TYPE 'UnliftedRep). a -> Box a
Box# a
Unlifted (Box a)
a

toBox :: PrimUnlifted a => a -> Box (Unlifted a)
toBox :: a -> Box (Unlifted a)
toBox a
a = Unlifted a -> Box (Unlifted a)
forall (a :: TYPE 'UnliftedRep). a -> Box a
Box# (a -> Unlifted a
forall a. PrimUnlifted a => a -> Unlifted a
toUnlifted# a
a)

fromBox :: PrimUnlifted a => Box (Unlifted a) -> a
fromBox :: Box (Unlifted a) -> a
fromBox (Box# Unlifted a
a) = Unlifted a -> a
forall a. PrimUnlifted a => Unlifted a -> a
fromUnlifted# Unlifted a
a