Line No. | Rev | Author | Line |
---|---|---|---|
1 | 1 | paulosilva | |
2 | {-# OPTIONS_GHC -Wall #-} | ||
3 | |||
4 | ------------------------------------------------------------------------------- | ||
5 | |||
6 | {- | | ||
7 | Module : Language.Type.Pretty | ||
8 | Description : Pretty-printer of the type representation. | ||
9 | Copyright : (c) Paulo Silva | ||
10 | License : LGPL | ||
11 | |||
12 | Maintainer : paufil@di.uminho.pt | ||
13 | Stability : experimental | ||
14 | Portability : portable | ||
15 | |||
16 | -} | ||
17 | |||
18 | |||
19 | ------------------------------------------------------------------------------- | ||
20 | |||
21 | module Language.Type.Pretty ( | ||
22 | showType | ||
23 | ) where | ||
24 | |||
25 | import {-# SOURCE #-} Language.Type.Syntax | ||
26 | |||
27 | showType :: Type t -> ShowS | ||
28 | showType (TVar a) = | ||
29 | parens $ | ||
30 | showString "TVar " . | ||
31 | showString a | ||
32 | |||
33 | showType One = showString "One" | ||
34 | showType Bool = showString "Bool" | ||
35 | showType Char = showString "Char" | ||
36 | showType String = showString "String" | ||
37 | showType Int = showString "Int" | ||
38 | showType Float = showString "Float" | ||
39 | |||
40 | showType (Prod a b) = | ||
41 | parens $ | ||
42 | showString "Prod " . | ||
43 | showType a . | ||
44 | space . | ||
45 | showType b | ||
46 | |||
47 | showType (Either a b) = | ||
48 | parens $ | ||
49 | showString "Either " . | ||
50 | showType a . | ||
51 | space . | ||
52 | showType b | ||
53 | |||
54 | showType (Maybe a) = | ||
55 | parens $ | ||
56 | showString "Maybe " . | ||
57 | showType a | ||
58 | |||
59 | showType (List a) = | ||
60 | parens $ | ||
61 | showString "List " . | ||
62 | showType a | ||
63 | |||
64 | showType (Set a) = | ||
65 | parens $ | ||
66 | showString "Set " . | ||
67 | showType a | ||
68 | |||
69 | showType (Map a b) = | ||
70 | parens $ | ||
71 | showString "Map " . | ||
72 | showType a . | ||
73 | space . | ||
74 | showType b | ||
75 | |||
76 | showType (Fun a b) = | ||
77 | parens $ | ||
78 | showString "Fun " . | ||
79 | showType a . | ||
80 | space . | ||
81 | showType b | ||
82 | |||
83 | showType (Rel a b) = | ||
84 | parens $ | ||
85 | showString "Rel " . | ||
86 | showType a . | ||
87 | space . | ||
88 | showType b | ||
89 | |||
90 | showType (Ord a) = | ||
91 | parens $ | ||
92 | showString "Ord " . | ||
93 | showType a | ||
94 | |||
95 | showType (GC a b) = | ||
96 | parens $ | ||
97 | showString "GC " . | ||
98 | showType a . | ||
99 | space . | ||
100 | showType b | ||
101 | |||
102 | ------------------------------------------------------------------------------- | ||
103 | |||
104 | parens :: ShowS -> String -> String | ||
105 | parens = showParen True | ||
106 | |||
107 | ------------------------------------------------------------------------------- | ||
108 | |||
109 | space :: ShowS | ||
110 | space = showChar ' ' | ||
111 | |||
112 | ------------------------------------------------------------------------------- | ||
113 |