-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.sml
More file actions
39 lines (33 loc) · 1.03 KB
/
Copy pathexample.sml
File metadata and controls
39 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
structure FppBasis = FppPrecedenceBasis (FppInitialBasis (FppPlainBasisTypes))
structure Fpp = FinalPrettyPrinter (FppBasis)
structure Render = FppRenderPlainText
structure Example =
struct
datatype tm = VAR of string | LAM of string * tm | APP of tm * tm
open FppBasis Fpp
fun @@ (f, x) = f x
infixr 0 @@
local
val initialEnv =
{maxWidth = 80,
maxRibbon = 60,
layout = FppTypes.BREAK,
failure = FppTypes.CANT_FAIL,
nesting = 0,
formatting = (),
formatAnn = fn _ => ()}
in
fun execPP (m : unit m) =
#output @@ m emptyPrecEnv initialEnv {curLine = [], maxWidthSeen = 0}
end
val rec ppTm : tm -> unit m =
fn VAR x => text x
| LAM (x, t) =>
grouped o atLevel 10 o nest 2 o hvsep @@
[hsep [text "lam", text "x", char #"."],
ppTm t]
| APP (t1, t2) =>
app (ppTm t1) [ppTm t2]
val example = LAM ("x", APP (VAR "x", APP (VAR "x", VAR "x")))
val () = Render.render TextIO.stdOut o execPP @@ ppTm example
end