1{-# LANGUAGE CPP #-}
2{-# LANGUAGE MagicHash #-}
3{-# LANGUAGE TemplateHaskell #-}
4
5#if MIN_VERSION_template_haskell(2,16,0)
6{-# LANGUAGE UnliftedNewtypes #-}
7#endif
8module Types (Foo(..)) where
9
10import Language.Haskell.TH.Syntax hiding (newName)
11
12#if MIN_VERSION_template_haskell(2,16,0)
13import GHC.Exts (Int#)
14import Language.Haskell.TH.Syntax.Compat
15#endif
16
17data Foo = MkFoo deriving (Eq, Show)
18
19-- An example of how to use liftTypedFromUntypedSplice to minimize the amount
20-- of CPP one has to use when manually defining `liftTyped` in `Lift` instance.
21-- This example is contrived, since you could just as well derive this
22-- particular `Lift` instance, but the same template will carry over to `Lift`
23-- instances that cannot be derived.
24instance Lift Foo where
25  lift MkFoo = [| MkFoo |]
26#if MIN_VERSION_template_haskell(2,16,0)
27  liftTyped = liftTypedFromUntypedSplice
28#endif
29
30#if MIN_VERSION_template_haskell(2,16,0)
31newtype UN = MkUN Int#
32
33-- An example of how to use unsafeSpliceCoerce to manually define liftTyped
34-- for an unlifted type in a backwards-compatible way. This example is
35-- contrived, since you could just as well derive this particular `Lift`
36-- instance, but the same template will carry over to `Lift` instances that
37-- cannot be derived.
38instance Lift UN where
39  lift (MkUN i#) = [| MkUN i# |]
40  liftTyped x = unsafeSpliceCoerce (lift x)
41#endif
42