blob: ba7de9f35cf317b62b535d5a8d8115b77e732020 (
plain) (
blame)
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
|
implementation module Util
import StdClass
from StdFunc import id, o
import StdInt
import StdList
import StdOverloaded
import StdString
from Text import class Text(concat), instance Text String
instance zero PrState
where
zero =
{ indent = 0
, output = []
}
printToString :: a -> String | print a
printToString x = concat (print x zero).output
instance print String where print s = \st -> {st & output=[s:st.output]}
instance print Int where print i = \st -> {st & output=[toString i:st.output]}
nl :: PrState -> PrState
nl st = {st & output=["\n":repeatn st.indent "\t"] ++ st.output}
indent :: PrState -> PrState
indent st = {st & indent=max 0 (st.indent - 1)}
unindent :: PrState -> PrState
unindent st = {st & indent=st.indent + 1}
prsperse :: (PrState -> PrState) [a] -> PrState -> PrState | print a
prsperse _ [] = id
prsperse _ [x] = print x
prsperse g [x:xs] = print x o g o prsperse g xs
|