summaryrefslogtreecommitdiff
path: root/src/Obs/Pretty.idr
diff options
context:
space:
mode:
authorGreg Brown <greg.brown01@ed.ac.uk>2023-01-03 13:46:38 +0000
committerGreg Brown <greg.brown01@ed.ac.uk>2023-01-03 13:46:38 +0000
commit3950a84c00f54ab39f2a209c368cc02460eeebd7 (patch)
treed44712a47db174b42ff545fec1b8c24530f76ce0 /src/Obs/Pretty.idr
parentc4bbe4ab5fa5953d468ac1509b37e03aace3085e (diff)
Add more program structure to abstract terms.
Add more program structure to type inference and checking.
Diffstat (limited to 'src/Obs/Pretty.idr')
-rw-r--r--src/Obs/Pretty.idr42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Obs/Pretty.idr b/src/Obs/Pretty.idr
new file mode 100644
index 0000000..52a358c
--- /dev/null
+++ b/src/Obs/Pretty.idr
@@ -0,0 +1,42 @@
+module Obs.Pretty
+
+import public Text.PrettyPrint.Prettyprinter
+
+-- ty is rendered Open
+export
+prettyDecl : (name : String) -> (ty : Doc ann) -> Doc ann
+prettyDecl name ty = parens $ group (pretty name <++> colon <+> line <+> align ty)
+
+-- ty and tail are rendered Open
+export
+prettyDeclForm : (prec : Prec) ->
+ (name : String) ->
+ (ty : Doc ann) ->
+ (sep : String) ->
+ (tail : Doc ann) ->
+ Doc ann
+prettyDeclForm d name ty sep tail =
+ parenthesise (d > Open) $ group $ vsep $ [prettyDecl name ty <++> pretty sep, align tail]
+
+-- body is rendered Open
+export
+prettyLambda : (prec : Prec) -> (name : String) -> (body : Doc ann) -> Doc ann
+prettyLambda d name body =
+ parenthesise (d >= App) $ group $ vsep [backslash <+> pretty name <++> pretty "=>", align body]
+
+-- head is rendered Open, tail are rendered App
+export
+prettyApp : (prec : Prec) -> (head : Doc ann) -> (tail : List (Doc ann)) -> Doc ann
+prettyApp d head tail = parenthesise (d >= App) $ group $ vsep (align head :: map (hang 2) tail)
+
+-- first and second are rendered Open
+export
+prettyPair : (first, second : Doc ann) -> Doc ann
+prettyPair first second =
+ angles $ group (neutral <++> align first <+> comma <+> line <+> align second <++> neutral)
+
+-- left and right are rendered Equal
+export
+prettyEqual : (prec : Prec) -> (left, right : Doc ann) -> Doc ann
+prettyEqual d left right =
+ parenthesise (d >= Equal) $ group $ vsep [align left <++> pretty "~", align right]