Skip to content

Commit 35c78c8

Browse files
author
Thomas Mahler
committed
keep compilation and simpflify separate
1 parent f45e88f commit 35c78c8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/CCC/Compiler.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module CCC.Compiler
3636

3737
import CCC.CatExpr (CatExpr (..))
3838
import CCC.Cat (fanC)
39-
import CCC.Rewrite (simplify)
4039
import Parser (Environment, Expr (..))
4140

4241
-- A closed morphism: valid in any input context z, i.e. a global element z → a.
@@ -65,7 +64,7 @@ newtype ClosedSel = ClosedSel (forall z. CatExpr z (CatExpr (Integer, Integer) I
6564
compileNumExpr :: Environment -> Expr -> CatExpr a Integer
6665
compileNumExpr env expr =
6766
case compileIntExpr env expr of
68-
Right (Closed cat) -> simplify cat
67+
Right (Closed cat) -> cat
6968
Left err -> error ("Structural compilation failed: " ++ err)
7069

7170
compileIntExpr :: Environment -> Expr -> Either String (Closed Integer)
@@ -446,8 +445,8 @@ compileEnvironment env = map compileBinding env
446445
where
447446
compileBinding (name, expr) =
448447
case compileExpr env [] expr of
449-
Right (SInt (Closed cat)) -> (name, show (simplify cat))
450-
Right (SSel (ClosedSel cat)) -> (name, show (simplify cat))
448+
Right (SInt (Closed cat)) -> (name, show cat)
449+
Right (SSel (ClosedSel cat)) -> (name, show cat)
451450
Right (SFun _) -> (name, "<lambda function>")
452451
Left err -> (name, "<compile error: " ++ err ++ ">")
453452

@@ -459,7 +458,7 @@ tryCompileVar env name =
459458
case lookup name env of
460459
Just expr ->
461460
case compileIntExpr env expr of
462-
Right (Closed cat) -> Right (simplify cat)
461+
Right (Closed cat) -> Right cat
463462
Left err -> Left $ "Expected numeric value for '" ++ name ++ "', got: " ++ err
464463
Nothing -> Left $ "Variable '" ++ name ++ "' not found in environment"
465464

src/CCC/Rewrite.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module CCC.Rewrite (simplify) where
1414
import CCC.Cat
1515
import CCC.CatExpr
1616
import Prelude hiding (id, (.))
17+
import Debug.Trace (trace)
1718

1819
type Rule = forall a b. CatExpr a b -> Maybe (CatExpr a b)
1920

@@ -94,7 +95,8 @@ recurseMatch :: Int -> Rule -> CatExpr a b -> Maybe (CatExpr a b)
9495
recurseMatch 0 _rule _x = Nothing
9596
recurseMatch depth rule x = case rule x of
9697
Nothing -> goDown (recurseMatch (depth -1) rule) x
97-
Just x' -> Just x'
98+
Just x' ->
99+
trace ("Rule applied: " ++ show rule ++ " to " ++ show x ++ " => " ++ show x') $ Just x'
98100

99101
goDown :: Rule -> Rule
100102
goDown z (Comp f g) = case z f of

0 commit comments

Comments
 (0)