-
Notifications
You must be signed in to change notification settings - Fork 1
/
Types.hs
74 lines (54 loc) · 1.28 KB
/
Types.hs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Types where
import DList
import LatexPrint
import Control.Monad.Except
import Control.Monad.Trans.Writer
type Field = String
type Name = String
type Error = String
type Log = DList Char
type RuleIdx = Int
-- Error handling
type ErrT = ExceptT Error
-- Scope checking logging
type LogT = WriterT Log
-- #### Non-field bindings and references ####
data RefType = VarBind | RecBind | Unknown
deriving (Eq,Ord,Show)
data Ref = V RefType Int
| F String
deriving (Eq,Ord,Show)
var :: Int -> Ref
var = V VarBind
rec :: Int -> Ref
rec = V RecBind
field :: String -> Ref
field = F
refBinding :: Ref -> String
refBinding = showRef
showRef :: Ref -> String
showRef (V c n) = toChar c:(map cUnd . show) n
toChar :: RefType -> Char
toChar b = case b of
VarBind -> 'x'
RecBind -> 'r'
Unknown -> 'u'
-- Subscripted numerals
cUnd :: Char -> Char
cUnd c = case c of
'0' -> '\8320'
'1' -> '\8321'
'2' -> '\8322'
'3' -> '\8323'
'4' -> '\8324'
'5' -> '\8325'
'6' -> '\8326'
'7' -> '\8327'
'8' -> '\8328'
'9' -> '\8329'
_ -> error "Only numeric characters may be subscripted"
-- ###########################################
instance LatexPrintable Ref where
latexPrint r = case r of
V rt n -> ltx $ toChar rt : "_" ++ show n
F s -> ltx . mathit $ s