remove unnecessary testing definition from CodeTypes.hs
[ghc-base.git] / GHC / HetMet / CodeTypes.hs
1 {-# OPTIONS -XModalTypes -XMultiParamTypeClasses #-}
2 module GHC.HetMet.CodeTypes (
3   hetmet_brak,
4   hetmet_esc,
5   hetmet_csp,
6   GuestIntegerLiteral, guestIntegerLiteral,
7   GuestStringLiteral, guestStringLiteral,
8   GuestCharLiteral, guestCharLiteral,
9   GuestLanguageMult, <[ (*) ]>,
10   GuestLanguageAdd,  <[ (+) ]>,
11   GuestLanguageSub,  <[ (-) ]>, <[ negate ]>,
12   GuestLanguageFromInteger, <[ fromInteger ]>,
13   GuestLanguageBool, <[ (||) ]>, <[ (&&) ]>, <[ true ]>, <[ false ]>, <[ ifThenElse ]>
14 ) where
15 import Prelude (Integer, String, Char, Bool, error)
16 import GHC.HetMet.GArrow
17
18 hetmet_brak :: forall c. forall a. a -> <[a]>@c
19 hetmet_brak = Prelude.error "hetmet_brak should never be evaluated; did you forget to compile with -fcoqpass?"
20
21 hetmet_esc  :: forall c. forall a. <[a]>@c -> a
22 hetmet_esc = Prelude.error "hetmet_esc should never be evaluated; did you forget to compile with -fcoqpass?"
23
24 hetmet_csp :: forall c. forall a. a -> a
25 hetmet_csp = Prelude.error "hetmet_csp should never be evaluated; did you forget to compile with -fcoqpass?"
26
27 {-
28 -- After the flattening pass the argument and result types of this
29 -- function are identical (for any instantiation), so the flattener
30 -- simply turns it into the identity function.  Its only purpose is to
31 -- act as a "safe type cast" during pre-flattening
32 -- type-inference/checking:
33 hetmet_flatten ::
34    forall g.
35     GArrow     g (**) =>
36     GArrowDrop g (**) =>
37     GArrowCopy g (**) =>
38     GArrowSwap g (**) =>
39     GArrowLoop g (**) =>
40       forall x y.
41          <[ x -> y ]>@g
42          ->
43          (g x y)
44 hetmet_flatten _ = Prelude.error "hetmet_flatten should never be evaluated; did you forget to compile with -fcoqpass?"
45 -}
46
47 class GuestIntegerLiteral c where
48   guestIntegerLiteral :: Integer -> <[ Integer ]>@c
49
50 class GuestStringLiteral c where
51   guestStringLiteral :: String -> <[ String ]>@c
52
53 class GuestCharLiteral c where
54   guestCharLiteral :: Char -> <[ Char ]>@c
55
56 -- Note that stringwise-identical identifiers at different syntactic
57 -- depths are different identifiers; for this reason the operators
58 -- below can have a different type at syntactical depth 1 than at
59 -- syntactical depth 0.
60
61 class GuestLanguageMult c t where
62   <[ (*)    ]> :: <[ t -> t -> t ]>@c
63
64 class GuestLanguageAdd c t where
65   <[ (+)    ]> :: <[ t -> t -> t ]>@c
66
67 class GuestLanguageSub c t where
68   <[ (-)    ]> :: <[ t -> t -> t ]>@c
69   <[ negate ]> :: <[ t -> t      ]>@c   -- used for unary (-)
70
71 class GuestLanguageFromInteger c t where
72   <[ fromInteger ]> :: <[ Integer -> t ]>@c
73
74 class GuestLanguageBool c where
75   <[ (||) ]>       :: <[ Bool -> Bool -> Bool ]>@c
76   <[ (&&) ]>       :: <[ Bool -> Bool -> Bool ]>@c
77   <[ true ]>       :: <[ Bool ]>@c
78   <[ false ]>      :: <[ Bool ]>@c
79   <[ ifThenElse ]> :: <[ Bool -> t -> t -> t ]>@c
80
81 -- For heterogeneous metaprogramming, the meaning of "running" a
82 -- program is fairly ambiguous, and moreover is highly sensitive to
83 -- which subclasses of GuestLanguage the expression assumes it is
84 -- dealing with.  For example, in homogeneous metaprogramming, "run"
85 -- has this type:
86 --
87 --  ga_run :: forall a. (forall c. <[a]>@c) -> a
88 --
89 -- However, an expression which uses, say (*) at level 1 will never
90 -- be able to be passed to this expression, since
91 --
92 --   square :: forall c t. GuestLanguageMult ct => <[t]>@c -> <[t]>@c
93 --   square x = <[ ~~x * ~~x ]>
94 --
95
96 -- So even though this expression is polymorphic in the environment
97 -- classifier "c", it isn't "polymorphic enough".  This isn't merely a
98 -- technical obstacle -- the more features you assume the guest
99 -- language has, the more work the "run" implementation is obligated
100 -- to perform, and the type system must track that obligation.
101 --
102 -- The upshot is that we can define special-purpose "run" classes such as:
103 --
104 --   class GuestLanguageRunMult t where
105 --     ga_runMult :: forall a. (forall c. GuestLanguageMult c t => <[a]>@c) -> a
106 --
107 -- Any implementation of this class will need to know how to interpret
108 -- the (*) operator.  Unfortunately, to my knowledge, there is no way
109 -- to quantify over type classes in the Haskell type system, which is
110 -- what we would need to define a type-class-indexed version of the
111 -- GuestLanguageRun class; if we could do that, then we would have:
112 --
113 --   class GuestLanguageRun ( t ::: * -> TYPECLASS ) where
114 --     ga_runMult :: forall a. (forall c. TYPECLASS c => <[a]>@c) -> a
115 --
116 -- It might be possible to pull this of using type families; I need to
117 -- look into that.
118