Skip to content

Commit 4829293

Browse files
committed
🧩 [consolidate]: Remove spurious projection form from core language, and desugar SExpr projections to d-projections.
1 parent 2805662 commit 4829293

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

src/Eval.purs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ eval γ e0 αs = do
129129
withMsg "Variable lookup" $ lookup' x γ
130130
Op op ->
131131
withMsg "Variable lookup" $ lookup' op γ
132-
Project e x -> do
133-
v <- eval γ e αs
134-
case v of
135-
Val _ _ (V.Dictionary (DictRep d)) ->
136-
withMsg "Dict lookup" (snd <$> lookup x d # orElse ("Key \"" <> x <> "\" not found"))
137-
_ -> throw $ "Found " <> prettyP v <> ", expected dictionary"
138132
DProject e x -> do
139133
v <- eval γ e αs
140134
v' <- eval γ x αs

src/Expr.purs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ data Expr a
3333
| Constr a Ctr (List (Expr a))
3434
| Matrix a (Expr a) (Var × Var) (Expr a)
3535
| Lambda a (Elim a)
36-
| Project (Expr a) Var
3736
| DProject (Expr a) (Expr a)
3837
| App (Expr a) (Expr a)
3938
| Let (VarDef a) (Expr a)
@@ -77,7 +76,6 @@ instance FV (Expr a) where
7776
fv (Constr _ _ es) = unions (fv <$> es)
7877
fv (Matrix _ e1 _ e2) = fv e1 ∪ fv e2
7978
fv (Lambda _ σ) = fv σ
80-
fv (Project e _) = fv e
8179
fv (DProject e x) = fv e ∪ fv x
8280
fv (App e1 e2) = fv e1 ∪ fv e2
8381
fv (Let def e) = fv def ∪ (fv e \\ bv def)
@@ -173,7 +171,6 @@ instance JoinSemilattice a => JoinSemilattice (Expr a) where
173171
join (Matrix α e1 (x × y) e2) (Matrix α' e1' (x' × y') e2') =
174172
Matrix (α ∨ α') (e1 ∨ e1') ((x ≜ x') × (y ≜ y')) (e2 ∨ e2')
175173
join (Lambda α σ) (Lambda α' σ') = Lambda (α ∨ α') (σ ∨ σ')
176-
join (Project e x) (Project e' x') = Project (e ∨ e') (x ≜ x')
177174
join (DProject e1 e2) (DProject e1' e2') = DProject (e1 ∨ e1') (e2 ∨ e2')
178175
join (App e1 e2) (App e1' e2') = App (e1 ∨ e1') (e2 ∨ e2')
179176
join (LetRec ρ e) (LetRec ρ' e') = LetRec (ρ ∨ ρ') (e ∨ e')
@@ -191,7 +188,6 @@ instance BoundedJoinSemilattice a => Expandable (Expr a) (Raw Expr) where
191188
expand (Matrix α e1 (x × y) e2) (Matrix _ e1' (x' × y') e2') =
192189
Matrix α (expand e1 e1') ((x ≜ x') × (y ≜ y')) (expand e2 e2')
193190
expand (Lambda α σ) (Lambda _ σ') = Lambda α (expand σ σ')
194-
expand (Project e x) (Project e' x') = Project (expand e e') (x ≜ x')
195191
expand (DProject e1 e2) (DProject e1' e2') = DProject (expand e1 e1') (expand e2 e2')
196192
expand (App e1 e2) (App e1' e2') = App (expand e1 e1') (expand e2 e2')
197193
expand (Let def e) (Let def' e') = Let (expand def def') (expand e e')
@@ -214,7 +210,6 @@ instance Vertices (Expr Vertex) where
214210
vertices e@(Constr α _ es) = singleton (DVertex (α × pack e)) ∪ unions (vertices <$> es)
215211
vertices e@(Matrix α e1 _ e2) = singleton (DVertex (α × pack e)) ∪ vertices e1 ∪ vertices e2
216212
vertices e@(Lambda α σ) = singleton (DVertex (α × pack e)) ∪ vertices σ
217-
vertices (Project e _) = vertices e
218213
vertices (DProject e e') = vertices e ∪ vertices e'
219214
vertices (App e1 e2) = vertices e1 ∪ vertices e2
220215
vertices (Let def e) = vertices def ∪ vertices e
@@ -275,7 +270,6 @@ instance Apply Expr where
275270
apply (Matrix fα fe1 (x × y) fe2) (Matrix α e1 (x' × y') e2) =
276271
Matrix (fα α) (fe1 <*> e1) ((x ≜ x') × (y ≜ y')) (fe2 <*> e2)
277272
apply (Lambda fα fσ) (Lambda α σ) = Lambda (fα α) (fσ <*> σ)
278-
apply (Project fe x) (Project e _) = Project (fe <*> e) x
279273
apply (DProject fd fk) (DProject d k) = DProject (fd <*> d) (fk <*> k)
280274
apply (App fe1 fe2) (App e1 e2) = App (fe1 <*> e1) (fe2 <*> e2)
281275
apply (Let (VarDef fσ fe1) fe2) (Let (VarDef σ e1) e2) = Let (VarDef (fσ <*> σ) (fe1 <*> e1)) (fe2 <*> e2)

src/Pretty.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ instance Highlightable a => Pretty (E.Expr a) where
270270
pretty (E.Matrix a e1 (i × j) e2) =
271271
highlightIf a $ matrix (pretty e1 <+> text "for" <+> pair text i j <+> text "in" <+> pretty e2)
272272
pretty (E.Lambda a o) = highlightIf a (text "lambda") <+> pretty o -- really?
273-
pretty (E.Project e x) = pretty e <> text "." <> pretty x
274273
pretty (E.DProject e x) = pretty e <> brackets (pretty x)
275274
pretty (E.App e e') = pretty e <> parens (pretty e') -- TODO
276275
pretty (E.Let (E.VarDef o e) e') = text "def" <+> pretty o <> block (pretty e) <++> pretty e'

src/SExpr.purs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,22 @@ exprFwd (Float α n) =
293293
pure $ (E.Float α n)
294294
exprFwd (Str α s) =
295295
pure $ E.Str α s
296-
exprFwd (Constr α c ss) = do
296+
exprFwd (Constr α c ss) =
297297
E.Constr α c <$> traverse desug ss
298298
exprFwd (Dictionary α sss) = do
299299
let ks × ss = unzip sss
300300
ks' <- traverse desug ks
301301
es <- traverse desug ss
302302
E.Dictionary α <$> pure (zipWith Pair ks' es)
303-
exprFwd (Matrix α s (x × y) s') = do
303+
exprFwd (Matrix α s (x × y) s') =
304304
E.Matrix α <$> desug s <@> x × y <*> desug s'
305305
exprFwd (Lambda μ) =
306306
E.Lambda top <$> desug μ
307-
exprFwd (Project s x) = do
308-
E.Project <$> desug s <@> x
309-
exprFwd (DProject s x) = do
307+
exprFwd (Project s x) =
308+
E.DProject <$> desug s <@> E.Str top x
309+
exprFwd (DProject s x) =
310310
E.DProject <$> desug s <*> desug x
311-
exprFwd (App s1 s2) = do
311+
exprFwd (App s1 s2) =
312312
E.App <$> desug s1 <*> desug s2
313313
exprFwd (BinaryApp s1 op s2) =
314314
E.App <$> (E.App (E.Op op) <$> desug s1) <*> desug s2
@@ -322,11 +322,11 @@ exprFwd (Paragraph elems) =
322322
paragraphFwd elems
323323
exprFwd (ListEmpty α) =
324324
pure $ enil α
325-
exprFwd (ListNonEmpty α s l) = do
325+
exprFwd (ListNonEmpty α s l) =
326326
econs α <$> desug s <*> desug l
327327
exprFwd (ListEnum s1 s2) =
328328
E.App <$> (E.App (E.Var "enumFromTo") <$> desug s1) <*> desug s2
329-
exprFwd (ListComp α s (ListCompGen p s' : qs)) = unsafePartial $ do
329+
exprFwd (ListComp α s (ListCompGen p s' : qs)) = unsafePartial $
330330
listCompFwd (α × (ListCompGen p s' : qs) × s)
331331
exprFwd (ListComp α s qs) =
332332
listCompFwd (α × qs × s)
@@ -353,8 +353,8 @@ exprBwd (E.Matrix α e1 _ e2) (Matrix _ s1 (x × y) s2) =
353353
Matrix α (desugBwd e1 s1) (x × y) (desugBwd e2 s2)
354354
exprBwd (E.Lambda _ σ) (Lambda μ) =
355355
Lambda (desugBwd σ μ)
356-
exprBwd (E.Project e x) (Project s _) =
357-
Project (desugBwd e s) x
356+
exprBwd (E.DProject ed _) (Project s x) =
357+
Project (desugBwd ed s) x
358358
exprBwd (E.DProject ed ek) (DProject sd sk) =
359359
DProject (exprBwd ed sd) (exprBwd ek sk)
360360
exprBwd (E.App e1 e2) (App s1 s2) =

0 commit comments

Comments
 (0)