File: Lift.hs

package info (click to toggle)
haskell-witch 1.2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: haskell: 3,144; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE ExplicitForAll #-}

module Witch.Lift where

import qualified Data.Typeable as Typeable
import qualified Language.Haskell.TH.Syntax as TH
import qualified Witch.TryFrom as TryFrom
import qualified Witch.Utility as Utility

-- | 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 source target m.
  ( TryFrom.TryFrom source target,
    TH.Lift target,
    Show source,
    Typeable.Typeable source,
    Typeable.Typeable target,
    TH.Quote m
  ) =>
  source ->
  TH.Code m target
liftedFrom = TH.liftTyped . Utility.unsafeFrom

-- | 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 target source m.
  ( TryFrom.TryFrom source target,
    TH.Lift target,
    Show source,
    Typeable.Typeable source,
    Typeable.Typeable target,
    TH.Quote m
  ) =>
  source ->
  TH.Code m target
liftedInto = liftedFrom