on master help sign in
Bracket lhs functions
523d238iko
src/Tix/Types.hs+17−17
@@ -161,7 +161,7 @@ instance Pretty DeBruijn where
161 pretty (DeBruijn i j) = "〚" <> pretty i <+> pretty j <> "〛"
161 pretty (DeBruijn i j) = "〚" <> pretty i <+> pretty j <> "〛"
162
162
163instance Pretty NType where
163instance Pretty NType where
164− pretty t = greekifyWith t $ prettyNType t
164+ pretty t = greekifyWith t $ prettyNType False t
165
165
166instance Pretty Scheme where
166instance Pretty Scheme where
167 pretty t = greekifyWith t $ prettyScheme t
167 pretty t = greekifyWith t $ prettyScheme t
@@ -189,21 +189,21 @@ getDeBurjin (DeBruijn i j) = do
189
189
190type PrettyM a = forall eff. Members '[Reader Depth, Reader (Map DeBruijn Text)] eff => Eff eff a
190type PrettyM a = forall eff. Members '[Reader Depth, Reader (Map DeBruijn Text)] eff => Eff eff a
191
191
192−prettyNType :: NType -> PrettyM (Doc ann)
192+prettyNType :: Bool -> NType -> PrettyM (Doc ann)
193−prettyNType (NTypeVariable x) = return $ pretty x
193+prettyNType _ (NTypeVariable x) = return $ pretty x
194−prettyNType (NBruijn x) =
194+prettyNType _ (NBruijn x) =
195 getDeBurjin x <&> \case
195 getDeBurjin x <&> \case
196 Nothing -> pretty x
196 Nothing -> pretty x
197 Just t -> pretty t
197 Just t -> pretty t
198−prettyNType (NAtomic x) = return $ pretty x
198+prettyNType _ (NAtomic x) = return $ pretty x
199−prettyNType (x :-> y) = descend $ do
199+prettyNType rhs (x :-> y) = descend $ do
200− x' <- prettyNType x
200+ x' <- prettyNType True x
201− y' <- prettyNType y
201+ y' <- prettyNType False y
202− return $ group $ x' <+> "->" <> line <> y'
202+ return $ group $ (if rhs then bracketed "(" ")" else id) $ x' <+> "->" <> line <> y'
203−prettyNType (List x) = descend $ do
203+prettyNType _ (List x) = descend $ do
204− x' <- prettyNType x
204+ x' <- prettyNType True x
205 return $ group $ bracketed "[" "]" x'
205 return $ group $ bracketed "[" "]" x'
206−prettyNType (NAttrSet m) = descend $ do
206+prettyNType _ (NAttrSet m) = descend $ do
207 decls <- prettyDecl `traverse` M.toAscList m
207 decls <- prettyDecl `traverse` M.toAscList m
208 return $ group $ bracketed "{" "}" $ vsep decls
208 return $ group $ bracketed "{" "}" $ vsep decls
209 where
209 where
@@ -227,18 +227,18 @@ prettyScheme u@(Preds cs :=> t) = do
227 prettyPred `traverse` cs <&> \case
227 prettyPred `traverse` cs <&> \case
228 [] -> mempty
228 [] -> mempty
229 cs' -> group (paren (vsep $ punctuate "," cs') <+> "=>" <> line)
229 cs' -> group (paren (vsep $ punctuate "," cs') <+> "=>" <> line)
230− t' <- prettyNType t
230+ t' <- prettyNType False t
231 return $ group $ foralls <> cs' <> t'
231 return $ group $ foralls <> cs' <> t'
232 where
232 where
233 prettyPred :: Pred -> PrettyM (Doc ann)
233 prettyPred :: Pred -> PrettyM (Doc ann)
234 prettyPred (h `HasField` (k, v)) = do
234 prettyPred (h `HasField` (k, v)) = do
235− h' <- prettyNType h
235+ h' <- prettyNType False h
236 v' <- prettyScheme v
236 v' <- prettyScheme v
237 return $ group $ group (h' <> nest 2 (line' <> "." <> pretty k <+> "=")) <> nest 2 (line <> v')
237 return $ group $ group (h' <> nest 2 (line' <> "." <> pretty k <+> "=")) <> nest 2 (line <> v')
238 prettyPred (Update x y z) = do
238 prettyPred (Update x y z) = do
239− x' <- prettyNType x
239+ x' <- prettyNType False x
240− y' <- prettyNType y
240+ y' <- prettyNType False y
241− z' <- prettyNType z
241+ z' <- prettyNType False z
242 return $ group $ paren x' <+> "//" <> line <> paren y' <+> "~" <> line <> paren z'
242 return $ group $ paren x' <+> "//" <> line <> paren y' <+> "~" <> line <> paren z'
243 paren = bracketed "(" ")"
243 paren = bracketed "(" ")"
244
244