c77320efd87727737f7fe8687a19a0c996fe8725
[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 the kind of the type
75 */
76 :: Kind = KStar | KArrow Kind Kind
77 genTypeKind :: Type -> Kind
78
79 /**
80 * Predicate whether the outer type is a builtin type
81 */
82 class isBuiltin a :: a -> Bool
83 instance isBuiltin Type, GType
84
85 /**
86 * Predicate whether the outer type is a basic type
87 * Int, Bool, Char, Real, World, File, Dynamic
88 */
89 class isBasic a :: a -> Bool
90 instance isBasic Type, GType
91
92 /**
93 * Replace builtin constructors with their pretty names
94 */
95 class replaceBuiltins a :: a -> a
96 instance replaceBuiltins Type, GType, GenType
97
98 /**
99 * Creates a deep representation of the type
100 */
101 generic gType a :: Box GType a
102 derive gType UNIT, EITHER, PAIR, CONS of gcd, FIELD of gfd, OBJECT of gtd, RECORD of grd
103 derive gType Int, Bool, Real, Char, World, File
104 derive gType (->)
105 derive gType ?#, ?, ?^
106 derive gType [], [! ], [ !], [!!], [#], [#!], {}, {!}, {#}, {32#}
107 derive gType (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)