-- data E = One | Zero | Minus E E | Div E E | IfZ E E E 

pprMain x = nil <> ppr 0 R x <> nil;

parensIf b x = if b then parens x else x;

-- TODO: Include an example that only has the "occurring-in-the-left" issue. 
ppr i d x = manyParens (ppr_ i d x);
ppr_ i d One         = text "1" ;
ppr_ i d Zero        = text "0" ;
ppr_ i d (Minus x y) = parensIf (i >= 1) ( group (ppr 0 L x <> line' <> text "-" <> line' <> ppr 1 R y ) );
ppr_ i d (Div   x y) = parensIf (i >= 2) ( group (ppr 1 L x <> line' <> text "/" <> line' <> ppr 2 R y ) );
ppr_ i d (IfZ x y z) = parensIf (d == L) $ group $ 
                                              text "if" <> nil <> ppr 0 R x <> nil <> text "then" <>
                                                nest 4 (line <> ppr 0 R y) <> 
                                              line <> text "else" <> 
                                                nest 4 (line <> ppr 0 R z);

manyParens d = d <+ parens (manyParens d);
parens d = text "(" <> nest 1 (nil <> d <> nil) <> text ")";
nil = text "" <+ (charOf isSpace <> nil);
line' = line <+ text "" ; 
