-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty.sml
More file actions
39 lines (27 loc) · 747 Bytes
/
pretty.sml
File metadata and controls
39 lines (27 loc) · 747 Bytes
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
infix 4 <+>
infixr 0 $
structure Pretty :> sig
type t = string
val $ : ('a -> 'b) * 'a -> 'b
val <> : t * t -> t
val <+> : t * t -> t
val paren : bool -> t -> t
val brace : t -> t
val bracket : t -> t
(* Without parentheses *)
val list : ('a -> t) -> 'a list -> t
end = struct
type t = string
fun f $ x = f x
fun x <> y = x ^ y
fun x <+> y = x <> " " <> y
fun paren true s = "(" <> s <> ")"
| paren false s = s
fun brace s = "{" <> s <> "}"
fun bracket s = "[" <> s <> "]"
fun non_empty f x [] = f x
| non_empty f x [y] = f x <> "," <+> f y
| non_empty f x (y :: zs) = f x <> "," <+> non_empty f y zs
fun list _ [] = ""
| list f (x :: xs) = non_empty f x xs
end