1
+ {-# LANGUAGE FlexibleContexts, TemplateHaskell #-}
1
2
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
2
3
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
3
4
module Language.Pcf (Ty (.. ), Exp (.. ), compile , output ) where
5
+
4
6
import Bound
5
7
import Control.Applicative
6
8
import Control.Monad
@@ -16,12 +18,12 @@ import qualified Data.Set as S
16
18
import Data.String
17
19
import Data.Traversable hiding (mapM )
18
20
import Language.C.DSL
19
- import Prelude.Extras
20
21
import Paths_pcf
22
+ import Data.Deriving
21
23
22
24
data Ty = Arr Ty Ty
23
25
| Nat
24
- deriving Eq
26
+ deriving ( Eq , Show )
25
27
26
28
data Exp a = V a
27
29
| App (Exp a ) (Exp a )
@@ -30,7 +32,12 @@ data Exp a = V a
30
32
| Fix Ty (Scope () Exp a )
31
33
| Suc (Exp a )
32
34
| Zero
33
- deriving (Eq , Functor , Foldable , Traversable )
35
+ deriving (Functor , Foldable , Traversable )
36
+
37
+ deriveShow1 ''Exp
38
+ deriveShow ''Exp
39
+ deriveEq1 ''Exp
40
+ deriveEq ''Exp
34
41
35
42
--------------------------------------------------------
36
43
--------------- Type Checking --------------------------
@@ -77,7 +84,7 @@ data ExpC a = VC a
77
84
| IfzC (ExpC a ) (ExpC a ) (Scope () ExpC a )
78
85
| SucC (ExpC a )
79
86
| ZeroC
80
- deriving (Eq , Functor , Foldable , Traversable )
87
+ deriving (Functor , Foldable , Traversable )
81
88
82
89
closConv :: Ord a => Exp a -> Gen a (ExpC a )
83
90
closConv (V a) = return (VC a)
@@ -109,14 +116,16 @@ closConv (Lam t bind) = do
109
116
110
117
data BindL a = RecL Ty [ExpL a ] (Scope Int ExpL a )
111
118
| NRecL Ty [ExpL a ] (Scope Int ExpL a )
112
- deriving (Eq , Functor , Foldable , Traversable )
119
+ deriving (Functor , Foldable , Traversable )
120
+
121
+
113
122
data ExpL a = VL a
114
123
| AppL (ExpL a ) (ExpL a )
115
124
| LetL [BindL a ] (Scope Int ExpL a )
116
125
| IfzL (ExpL a ) (ExpL a ) (Scope () ExpL a )
117
126
| SucL (ExpL a )
118
127
| ZeroL
119
- deriving (Eq , Functor , Foldable , Traversable )
128
+ deriving (Functor , Foldable , Traversable )
120
129
121
130
trivLetBody :: Scope Int ExpL a
122
131
trivLetBody = fromJust . closed . abstract (const $ Just 0 ) $ VL ()
@@ -153,17 +162,28 @@ type NumArgs = Int
153
162
data BindTy = Int | Clos deriving Eq
154
163
155
164
data FauxCTop a = FauxCTop Integer NumArgs (Scope Int FauxC a )
156
- deriving (Eq , Functor , Foldable , Traversable )
165
+ deriving (Functor , Foldable , Traversable )
166
+
157
167
data BindFC a = NRecFC Integer [FauxC a ]
158
168
| RecFC BindTy Integer [FauxC a ]
159
- deriving (Eq , Functor , Foldable , Traversable )
169
+ deriving (Functor , Foldable , Traversable )
170
+
160
171
data FauxC a = VFC a
161
172
| AppFC (FauxC a ) (FauxC a )
162
173
| IfzFC (FauxC a ) (FauxC a ) (Scope () FauxC a )
163
174
| LetFC [BindFC a ] (Scope Int FauxC a )
164
175
| SucFC (FauxC a )
165
176
| ZeroFC
166
- deriving (Eq , Functor , Foldable , Traversable )
177
+ deriving (Functor , Foldable , Traversable )
178
+
179
+ deriveEq1 ''FauxCTop
180
+ deriveEq ''FauxCTop
181
+
182
+ deriveEq1 ''FauxC
183
+ deriveEq ''FauxC
184
+
185
+ deriveEq1 ''BindFC
186
+ deriveEq ''BindFC
167
187
168
188
type FauxCM a = WriterT [FauxCTop a ] (Gen a )
169
189
@@ -295,7 +315,6 @@ output e = case compile e of
295
315
------------------- Extremely Boring Instances --------------------
296
316
-------------------------------------------------------------------
297
317
298
- instance Eq1 Exp where
299
318
instance Applicative Exp where
300
319
pure = return
301
320
(<*>) = ap
@@ -309,7 +328,6 @@ instance Monad Exp where
309
328
Suc e >>= f = Suc (e >>= f)
310
329
Zero >>= _ = Zero
311
330
312
- instance Eq1 ExpC where
313
331
instance Applicative ExpC where
314
332
pure = return
315
333
(<*>) = ap
@@ -323,7 +341,6 @@ instance Monad ExpC where
323
341
SucC e >>= f = SucC (e >>= f)
324
342
ZeroC >>= _ = ZeroC
325
343
326
- instance Eq1 ExpL where
327
344
instance Applicative ExpL where
328
345
pure = return
329
346
(<*>) = ap
@@ -338,7 +355,6 @@ instance Monad ExpL where
338
355
where go (RecL t es scope) = RecL t (map (>>= f) es) (scope >>>= f)
339
356
go (NRecL t es scope) = NRecL t (map (>>= f) es) (scope >>>= f)
340
357
341
- instance Eq1 FauxC where
342
358
instance Applicative FauxC where
343
359
pure = return
344
360
(<*>) = ap
0 commit comments