Commits

Aleksey Khudyakov  committed adbcc42

Less brackets

  • Participants
  • Parent commits 7ee1ddb

Comments (0)

Files changed (1)

File Data/Lambda/Simple.hs

 prettyUnicode = PrettyLambda 'λ' " → "
 
 
+brackets :: String -> String
+brackets s = '(' : s ++ ")"
+
+br :: Term v -> String -> String 
+br (Variable _)           = id
+br _                      = brackets
 
 -- | Pretty print lambda expression
 pretty :: ShowVar v => PrettyLambda -> Term v -> String
 pretty _ (Variable v) = showVar v
-pretty d (Apply  a b) = printf "(%s %s)" (pretty d a) (pretty d b)
-pretty d t@(Lam  _ _) = '(' : lambdaChar d : lamWorker d "" t ++ ")"
+pretty d (Apply t q) = br t (pretty d t) ++ " " ++ br q (pretty d q)
+pretty d t@(Lam  _ _) = lambdaChar d : lamWorker d "" t
 
 -- Special case: currying
 lamWorker :: ShowVar v => PrettyLambda -> String -> Term v -> String
 niceNames :: Term (Var String) -> Term String
 niceNames = worker (names ['a'..'z']) (Map.empty) 
   where
-    worker _ m (Variable v)  = Variable $ m Map.! v
-    worker s m (Apply t1 t2) = Apply (worker s m t1) (worker s m t2)
+    worker _      m (Variable v)  = Variable $ m Map.! v
+    worker s      m (Apply t1 t2) = Apply (worker s m t1) (worker s m t2)
     worker (nm:s) m (Lam v t) = 
       Lam nm $ worker s (Map.insert v nm m) t