packages feed

witch-0.2.1.1 / src / ghc-8.8 / Witch / Lift.hs

{-# LANGUAGE AllowAmbiguousTypes #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE TypeFamilies #-}module Witch.Lift whereimport qualified Data.Typeable as Typeableimport qualified Language.Haskell.TH.Syntax as THimport qualified Witch.Identity as Identityimport qualified Witch.TryCast as TryCastimport qualified Witch.Utility as Utility-- | This is like 'Utility.unsafeCast' except that it works at compile time-- rather than runtime.---- > -- Avoid this:-- > unsafeCast "some literal"-- >-- > -- Prefer this:-- > $$(liftedCast "some literal")liftedCast  :: forall source target   . ( TryCast.TryCast source target     , TH.Lift target     , Show source     , Typeable.Typeable source     , Typeable.Typeable target     )  => source  -> TH.Q (TH.TExp target)liftedCast s = TH.unsafeTExpCoerce $ TH.lift (Utility.unsafeCast s :: target)-- | This is like 'Utility.unsafeFrom' except that it works at compile time-- rather than runtime.---- > -- Avoid this:-- > unsafeFrom @s "some literal"-- >-- > -- Prefer this:-- > $$(liftedFrom @s "some literal")liftedFrom  :: forall s target source   . ( Identity.Identity s ~ source     , TryCast.TryCast source target     , TH.Lift target     , Show source     , Typeable.Typeable source     , Typeable.Typeable target     )  => source  -> TH.Q (TH.TExp target)liftedFrom = liftedCast-- | This is like 'Utility.unsafeInto' except that it works at compile time-- rather than runtime.---- > -- Avoid this:-- > unsafeInto @t "some literal"-- >-- > -- Prefer this:-- > $$(liftedInto @t "some literal")liftedInto  :: forall t source target   . ( Identity.Identity t ~ target     , TryCast.TryCast source target     , TH.Lift target     , Show source     , Typeable.Typeable source     , Typeable.Typeable target     )  => source  -> TH.Q (TH.TExp target)liftedInto = liftedCast