@@ -26,8 +26,8 @@ deriving instance Binary CaseAlt
28type CaseTree = SC
28type CaseTree = SC
29−type Clause = ([Pat], Term)
29+type Clause = ([Pat], (Term, Term))
30−type CS = Int
30+type CS = ([Term], Int)
32-- simple terms can be inlined trivially - good for primitives in particular
32-- simple terms can be inlined trivially - good for primitives in particular
33small :: SC -> Bool
33small :: SC -> Bool
@@ -36,13 +36,13 @@ small _ = False
37simpleCase :: Bool -> Bool -> [(Term, Term)] -> CaseDef
37simpleCase :: Bool -> Bool -> [(Term, Term)] -> CaseDef
38simpleCase tc cover []
38simpleCase tc cover []
39− = CaseDef [] (UnmatchedCase "No pattern clauses")
39+ = CaseDef [] (UnmatchedCase "No pattern clauses") []
40simpleCase tc cover cs
40simpleCase tc cover cs
41− = let pats = map (\ (l, r) -> (toPats tc l, r)) cs
41+ = let pats = map (\ (l, r) -> (toPats tc l, (l, r))) cs
42− numargs = length (fst (head pats))
42+ numargs = length (fst (head pats))
43− ns = take numargs args
43+ ns = take numargs args
44− tree = evalState (match ns pats (defaultCase cover)) numargs in
44+ (tree, st) = runState (match ns pats (defaultCase cover)) ([], numargs) in
45− CaseDef ns (prune tree)
45+ CaseDef ns (prune tree) (fst st)
46 where args = map (\i -> MN i "e") [0..]
46 where args = map (\i -> MN i "e") [0..]
47 defaultCase True = STerm Erased
47 defaultCase True = STerm Erased
48 defaultCase False = UnmatchedCase "Error"
48 defaultCase False = UnmatchedCase "Error"
@@ -109,8 +109,12 @@ partition xs = error $ "Partition " ++ show xs
110match :: [Name] -> [Clause] -> SC -- error case
110match :: [Name] -> [Clause] -> SC -- error case
111 -> State CS SC
111 -> State CS SC
112+match [] (([], ret) : xs) err
114+ put (ts ++ (map (fst.snd) xs), v)
112−match [] (([], ret) : _) err = return $ STerm ret -- run out of arguments
115+ return $ STerm (snd ret) -- run out of arguments
113−match vs cs err = mixture vs (partition cs) err
116+match vs cs err = do cs <- mixture vs (partition cs) err
115mixture :: [Name] -> [Partition] -> SC -> State CS SC
119mixture :: [Name] -> [Partition] -> SC -> State CS SC
116mixture vs [] err = return err
120mixture vs [] err = return err
@@ -166,7 +170,7 @@ argsToAlt rs@((r, m) : _)
166 addRs ((r, (ps, res)) : rs) = ((r++ps, res) : addRs rs)
170 addRs ((r, (ps, res)) : rs) = ((r++ps, res) : addRs rs)
168getVar :: State CS Name
172getVar :: State CS Name
169−getVar = do v <- get; put (v+1); return (MN v "e")
173+getVar = do (t, v) <- get; put (t, v+1); return (MN v "e")
171groupCons :: [Clause] -> State CS [Group]
175groupCons :: [Clause] -> State CS [Group]
172groupCons cs = gc [] cs
176groupCons cs = gc [] cs
@@ -195,7 +199,7 @@ varRule (v : vs) alts err =
195 do let alts' = map (repVar v) alts
199 do let alts' = map (repVar v) alts
196 match vs alts' err
200 match vs alts' err
198− repVar v (PV p : ps , res) = (ps, subst p (P Bound v (V 0)) res)
202+ repVar v (PV p : ps , (lhs, res)) = (ps, (lhs, subst p (P Bound v (V 0)) res))
199 repVar v (PAny : ps , res) = (ps, res)
203 repVar v (PAny : ps , res) = (ps, res)
201prune :: SC -> SC
205prune :: SC -> SC