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