c01eca96469050b76ef4080a5961fafba88f828f
[clean-tests.git] / gengen / Data / GenType.dcl
1 definition module Data.GenType
2
3 import StdGeneric
4 from StdOverloaded import class ==, class toString
5
6 :: Box b a =: Box b
7 derive bimap Box
8 unBox (Box b) :== b
9 box b :== Box b
10 reBox x :== box (unBox x)
11
12 :: GType
13 = GTyBasic BasicType
14 | GTyRef String
15 | GTyArrow GType GType
16 | GTyArray ArrayType GType
17 | GTyUList UListType GType
18 | GTyUMaybe GType
19 | GTyUnit
20 | GTyEither GType GType
21 | GTyPair GType GType
22 | GTyCons GenericConsDescriptor GType
23 | GTyField GenericFieldDescriptor GType
24 | GTyObject GenericTypeDefDescriptor GType
25 | GTyRecord GenericRecordDescriptor GType
26
27 :: Type
28 = TyBasic BasicType
29 | TyRef String
30 | TyArrow Type Type
31 | TyArray ArrayType Type
32 | TyUList UListType Type
33 | TyUMaybe Type
34 | TyNewType GenericTypeDefDescriptor GenericConsDescriptor Type
35 | TyObject GenericTypeDefDescriptor [(GenericConsDescriptor, [Type])]
36 | TyRecord GenericRecordDescriptor [(GenericFieldDescriptor, Type)]
37
38 :: BasicType = BTInt | BTChar | BTReal | BTBool | BTDynamic | BTFile | BTWorld
39 :: ArrayType = AStrict | ALazy | AUnboxed | APacked
40 :: UListType = ULLazy | ULStrict
41
42 instance == GType, Type, BasicType, ArrayType, UListType, GenType
43 instance toString GType, Type, BasicType, ArrayType, UListType, GenType
44
45 /**
46 * Removes recursive types by replacing them with references
47 *
48 * @param gtype
49 * @result the main type
50 * @result all the separate types grouped in the strongly connected components
51 */
52 flattenGType :: GType -> [[GType]]
53
54 /**
55 * Convert a GType to a Type. This always returns a Just if the GType was
56 * constructed using the gType generic function
57 *
58 * @param gtype
59 * @result a type on success
60 */
61 gTypeToType :: GType -> Type
62
63 /**
64 * Gives the name for the type
65 */
66 typeName :: Type -> String
67
68 /**
69 * Gives the genType for a type
70 */
71 typeGenType :: Type -> [GenType]
72
73 /**
74 * Return an approximation of the kind of the type given all the constructors
75 */
76 :: Kind = KStar | (KArrow) infixr 1 Kind Kind
77 genTypeKind :: [GenType] -> Kind
78 instance toString Kind
79
80 /**
81 * Predicate whether the outer type is a builtin type
82 */
83 class isBuiltin a :: a -> Bool
84 instance isBuiltin Type, GType
85
86 /**
87 * Predicate whether the outer type is a basic type
88 * Int, Bool, Char, Real, World, File, Dynamic
89 */
90 class isBasic a :: a -> Bool
91 instance isBasic Type, GType
92
93 /**
94 * Replace builtin constructors with their pretty names
95 */
96 class replaceBuiltins a :: a -> a
97 instance replaceBuiltins Type, GType, GenType
98
99 /**
100 * Creates a deep representation of the type
101 */
102 generic gType a :: Box GType a
103 derive gType UNIT, EITHER, PAIR, CONS of gcd, FIELD of gfd, OBJECT of gtd, RECORD of grd
104 derive gType Int, Bool, Real, Char, World, File
105 derive gType (->)
106 derive gType ?#, ?, ?^
107 derive gType [], [! ], [ !], [!!], [#], [#!], {}, {!}, {#}, {32#}
108 derive gType (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)