on master help sign in
Better rendering of case trees in debug info
76442a7Edwin Brady
src/Core/CaseTree.hs+22−1
@@ -17,7 +17,7 @@ data SC = Case Name [CaseAlt] -- invariant: lowest tags first
17 | ProjCase Term [CaseAlt] -- special case for projections
17 | ProjCase Term [CaseAlt] -- special case for projections
18 | STerm Term
18 | STerm Term
19 | UnmatchedCase String -- error message
19 | UnmatchedCase String -- error message
20− deriving (Show, Eq, Ord)
20+ deriving (Eq, Ord)
21{-!
21{-!
22deriving instance Binary SC
22deriving instance Binary SC
23!-}
23!-}
@@ -30,6 +30,27 @@ data CaseAlt = ConCase Name Int [Name] SC
30deriving instance Binary CaseAlt
30deriving instance Binary CaseAlt
31!-}
31!-}
32
32
33+instance Show SC where
34+ show sc = show' 1 sc
35+ where
36+ show' i (Case n alts) = "case " ++ show n ++ " of\n" ++ indent i ++
37+ showSep ("\n" ++ indent i) (map (showA i) alts)
38+ show' i (ProjCase tm alts) = "case " ++ show tm ++ " of " ++
39+ showSep ("\n" ++ indent i) (map (showA i) alts)
40+ show' i (STerm tm) = show tm
41+ show' i (UnmatchedCase str) = "error " ++ show str
42+
43+ indent i = concat $ take i (repeat " ")
44+
45+ showA i (ConCase n t args sc)
46+ = show n ++ "(" ++ showSep (", ") (map show args) ++ ") => "
47+ ++ show' (i+1) sc
48+ showA i (ConstCase t sc)
49+ = show t ++ " => " ++ show' (i+1) sc
50+ showA i (DefaultCase sc)
51+ = "_ => " ++ show' (i+1) sc
52+
53+
33type CaseTree = SC
54type CaseTree = SC
34type Clause = ([Pat], (Term, Term))
55type Clause = ([Pat], (Term, Term))
35type CS = ([Term], Int)
56type CS = ([Term], Int)