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