{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE UnliftedNewtypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE InstanceSigs #-}
module Data.Elevator.Internal where
import GHC.Exts
import Data.Kind
import Unsafe.Coerce
type LiftedType = Type
type U = UnliftedType
type L = LiftedType
type role Strict representational
newtype Strict (a :: LiftedType) where
Strict_ :: Any @UnliftedType -> Strict a
toStrict# :: a -> Strict a
toStrict# :: forall a. a -> Strict a
toStrict# = (Any -> Any) -> a -> Strict a
forall a b. a -> b
unsafeCoerce Any -> Any
forall a. a -> a
id
fromStrict# :: Strict a -> a
fromStrict# :: forall a. Strict a -> a
fromStrict# = (Any -> Any) -> Strict a -> a
forall a b. a -> b
unsafeCoerce Any -> Any
forall a. a -> a
id
pattern Strict :: a -> Strict a
pattern $mStrict :: forall {r} {a}. Strict a -> (a -> r) -> ((# #) -> r) -> r
$bStrict :: forall a. a -> Strict a
Strict x <- (fromStrict# -> x) where
Strict a
x = a -> Strict a
forall a. a -> Strict a
toStrict# a
x
{-# INLINE Strict #-}
{-# COMPLETE Strict #-}
type role Lazy representational
newtype Lazy (a :: UnliftedType) where
Lazy_ :: Any @LiftedType -> Lazy a
toLazy# :: a -> Lazy a
toLazy# :: forall (a :: UnliftedType). a -> Lazy a
toLazy# = (Any -> Any) -> a -> Lazy a
forall a b. a -> b
unsafeCoerce Any -> Any
forall a. a -> a
id
fromLazy# :: Lazy a -> a
fromLazy# :: forall (a :: UnliftedType). Lazy a -> a
fromLazy# = (Any -> Any) -> Lazy a -> a
forall a b. a -> b
unsafeCoerce Any -> Any
forall a. a -> a
id
pattern Lazy :: a -> Lazy a
pattern $mLazy :: forall {r} {a :: UnliftedType}.
Lazy a -> (a -> r) -> ((# #) -> r) -> r
$bLazy :: forall (a :: UnliftedType). a -> Lazy a
Lazy x <- (fromLazy# -> x) where
Lazy a
x = a -> Lazy a
forall (a :: UnliftedType). a -> Lazy a
toLazy# a
x
{-# INLINE Lazy #-}
{-# COMPLETE Lazy #-}
levCoerce :: LevitySubsumption a b => a -> b
levCoerce :: forall a b. LevitySubsumption a b => a -> b
levCoerce = a -> b
forall a b. LevitySubsumption a b => a -> b
levCoerce#
class LevitySubsumption (a :: TYPE (BoxedRep l)) (b :: TYPE (BoxedRep r)) where
levCoerce# :: a -> b
instance {-# OVERLAPPABLE #-} LevitySubsumption (a::LiftedType) a where
levCoerce# :: a -> a
levCoerce# a
x = a
x
instance {-# OVERLAPPABLE #-} LevitySubsumption (a::UnliftedType) a where
levCoerce# :: a -> a
levCoerce# a
x = a
x
instance {-# OVERLAPPING #-} LevitySubsumption (Strict a) a where
levCoerce# :: Strict a -> a
levCoerce# (Strict a
a) = a
a
instance {-# OVERLAPPING #-} LevitySubsumption a (Lazy a) where
levCoerce# :: a -> Lazy a
levCoerce# a
a = a -> Lazy a
forall (a :: UnliftedType). a -> Lazy a
Lazy a
a
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::L)) ((a2::L) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::L)) ((a2::L) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::L)) ((a2::U) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::L)) ((a2::U) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::U)) ((a2::L) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::U)) ((a2::L) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::U)) ((a2::U) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::L) -> (b1::U)) ((a2::U) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::L)) ((a2::L) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::L)) ((a2::L) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::L)) ((a2::U) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::L)) ((a2::U) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::U)) ((a2::L) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::U)) ((a2::L) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::U)) ((a2::U) -> (b2::L)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x
instance {-# OVERLAPPING #-} (LevitySubsumption a2 a1, LevitySubsumption b1 b2) => LevitySubsumption ((a1::U) -> (b1::U)) ((a2::U) -> (b2::U)) where
levCoerce# :: (a1 -> b1) -> a2 -> b2
levCoerce# a1 -> b1
f a2
x = (a1 -> b1) -> a2 -> b2
forall a b. a -> b
unsafeCoerce# a1 -> b1
f a2
x