Skip to content

Commit fa7ca44

Browse files
authored
Merge pull request #2 from siraben/rebuild
Make it buildable again, and some enchancements to explanation.md
2 parents 004e2f7 + 83af128 commit fa7ca44

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

cabal.project

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: *
2+
allow-newer: c-dsl:*

explanation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ said it would so we use `assertTy`. For a lambda we infer the body
160160
type and return a function from the given argument type to the body
161161
type.
162162

163-
```
163+
``` haskell
164164
typeCheck env (Ifz i t e) = do
165165
assertTy env i Nat
166166
ty <- typeCheck env t
@@ -443,7 +443,7 @@ lifting out of the program. Thus we use `WriterT` to gather a lift of
443443
toplevel functions as we traverse the program. Other than that this is
444444
much like what we've seen before.
445445

446-
```
446+
``` haskell
447447
type FauxCM a = WriterT [FauxCTop a] (Gen a)
448448

449449
fauxc :: ExpL Integer -> FauxCM Integer (FauxC Integer)

pcf.cabal

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ library
2727
hs-source-dirs: src
2828
exposed-modules: Language.Pcf
2929
other-modules: Paths_pcf
30-
build-depends: base >=4.0 && <5
31-
, bound == 1.*
30+
build-depends: base ==4.*
31+
, bound
3232
, c-dsl
3333
, containers >= 0.5
3434
, monad-gen
35-
, mtl == 2.*
36-
, prelude-extras
35+
, mtl
3736
, transformers
3837
, void
38+
, deriving-compat
3939
default-language: Haskell2010

src/Language/Pcf.hs

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
{-# LANGUAGE FlexibleContexts, TemplateHaskell #-}
12
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
23
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
34
module Language.Pcf (Ty(..), Exp(..), compile, output) where
5+
46
import Bound
57
import Control.Applicative
68
import Control.Monad
@@ -16,12 +18,12 @@ import qualified Data.Set as S
1618
import Data.String
1719
import Data.Traversable hiding (mapM)
1820
import Language.C.DSL
19-
import Prelude.Extras
2021
import Paths_pcf
22+
import Data.Deriving
2123

2224
data Ty = Arr Ty Ty
2325
| Nat
24-
deriving Eq
26+
deriving (Eq, Show)
2527

2628
data Exp a = V a
2729
| App (Exp a) (Exp a)
@@ -30,7 +32,12 @@ data Exp a = V a
3032
| Fix Ty (Scope () Exp a)
3133
| Suc (Exp a)
3234
| 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
3441

3542
--------------------------------------------------------
3643
--------------- Type Checking --------------------------
@@ -77,7 +84,7 @@ data ExpC a = VC a
7784
| IfzC (ExpC a) (ExpC a) (Scope () ExpC a)
7885
| SucC (ExpC a)
7986
| ZeroC
80-
deriving (Eq, Functor, Foldable, Traversable)
87+
deriving (Functor, Foldable, Traversable)
8188

8289
closConv :: Ord a => Exp a -> Gen a (ExpC a)
8390
closConv (V a) = return (VC a)
@@ -109,14 +116,16 @@ closConv (Lam t bind) = do
109116

110117
data BindL a = RecL Ty [ExpL a] (Scope Int ExpL a)
111118
| NRecL Ty [ExpL a] (Scope Int ExpL a)
112-
deriving (Eq, Functor, Foldable, Traversable)
119+
deriving (Functor, Foldable, Traversable)
120+
121+
113122
data ExpL a = VL a
114123
| AppL (ExpL a) (ExpL a)
115124
| LetL [BindL a] (Scope Int ExpL a)
116125
| IfzL (ExpL a) (ExpL a) (Scope () ExpL a)
117126
| SucL (ExpL a)
118127
| ZeroL
119-
deriving (Eq, Functor, Foldable, Traversable)
128+
deriving (Functor, Foldable, Traversable)
120129

121130
trivLetBody :: Scope Int ExpL a
122131
trivLetBody = fromJust . closed . abstract (const $ Just 0) $ VL ()
@@ -153,17 +162,28 @@ type NumArgs = Int
153162
data BindTy = Int | Clos deriving Eq
154163

155164
data FauxCTop a = FauxCTop Integer NumArgs (Scope Int FauxC a)
156-
deriving (Eq, Functor, Foldable, Traversable)
165+
deriving (Functor, Foldable, Traversable)
166+
157167
data BindFC a = NRecFC Integer [FauxC a]
158168
| RecFC BindTy Integer [FauxC a]
159-
deriving (Eq, Functor, Foldable, Traversable)
169+
deriving (Functor, Foldable, Traversable)
170+
160171
data FauxC a = VFC a
161172
| AppFC (FauxC a) (FauxC a)
162173
| IfzFC (FauxC a) (FauxC a) (Scope () FauxC a)
163174
| LetFC [BindFC a] (Scope Int FauxC a)
164175
| SucFC (FauxC a)
165176
| 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
167187

168188
type FauxCM a = WriterT [FauxCTop a] (Gen a)
169189

@@ -295,7 +315,6 @@ output e = case compile e of
295315
------------------- Extremely Boring Instances --------------------
296316
-------------------------------------------------------------------
297317

298-
instance Eq1 Exp where
299318
instance Applicative Exp where
300319
pure = return
301320
(<*>) = ap
@@ -309,7 +328,6 @@ instance Monad Exp where
309328
Suc e >>= f = Suc (e >>= f)
310329
Zero >>= _ = Zero
311330

312-
instance Eq1 ExpC where
313331
instance Applicative ExpC where
314332
pure = return
315333
(<*>) = ap
@@ -323,7 +341,6 @@ instance Monad ExpC where
323341
SucC e >>= f = SucC (e >>= f)
324342
ZeroC >>= _ = ZeroC
325343

326-
instance Eq1 ExpL where
327344
instance Applicative ExpL where
328345
pure = return
329346
(<*>) = ap
@@ -338,7 +355,6 @@ instance Monad ExpL where
338355
where go (RecL t es scope) = RecL t (map (>>= f) es) (scope >>>= f)
339356
go (NRecL t es scope) = NRecL t (map (>>= f) es) (scope >>>= f)
340357

341-
instance Eq1 FauxC where
342358
instance Applicative FauxC where
343359
pure = return
344360
(<*>) = ap

0 commit comments

Comments
 (0)