@@ -104,14 +104,20 @@ relationAsTable rel@(Relation _ tupleSet) = (header, body)
104104 body = L.foldl' tupleFolder [] (asList tupleSet)
105105 tupleFolder acc tuple = acc ++ [map (\attrName -> case atomForAttributeName attrName tuple of
106106 Left _ -> "?"
107− Right atom -> showAtom atom
107+ Right atom -> showAtom 0 atom
108108 ) oAttrNames]
109109
110−showAtom :: Atom -> StringType
111−showAtom (Atom atom) = case cast atom of
112− Just rel -> renderTable $ relationAsTable rel
113− Nothing -> toText atom
114−showAtom (ConstructedAtom dConsName _ atoms) = dConsName `T.append` " " `T.append` T.concat (L.intersperse " " (map showAtom atoms))
110+showParens :: Bool -> StringType -> StringType
111+showParens predicate f = if predicate then
112+ "(" `T.append` f `T.append` ")"
113+ else
114+ f
115+
116+showAtom :: Int -> Atom -> StringType
117+showAtom _ (Atom atom) = case cast atom of
118+ Just rel -> renderTable $ relationAsTable rel
119+ Nothing -> toText atom
120+showAtom level (ConstructedAtom dConsName _ atoms) = showParens (level >= 1 && length atoms >= 1) $ T.concat (L.intersperse " " (dConsName : (map (showAtom 1) atoms)))
115121
116122renderTable :: Table -> StringType
117123renderTable table = renderHeader table (fst cellLocs) `T.append` renderBody (snd table) cellLocs