gengeng
[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 * Predicate whether the outer type is a builtin type
70 */
71 class isBuiltin a :: a -> Bool
72 instance isBuiltin Type, GType
73
74 /**
75 * Predicate whether the outer type is a basic type
76 * Int, Bool, Char, Real, World, File, Dynamic
77 */
78 class isBasic a :: a -> Bool
79 instance isBasic Type, GType
80
81 /**
82 * Replace builtin constructors with their pretty names
83 */
84 class replaceBuiltins a :: a -> a
85 instance replaceBuiltins Type, GType, GenType
86
87 /**
88 * Creates a deep representation of the type
89 */
90 generic gType a :: Box GType a
91 derive gType UNIT, EITHER, PAIR, CONS of gcd, FIELD of gfd, OBJECT of gtd, RECORD of grd
92 derive gType Int, Bool, Real, Char, World, File
93 derive gType (->)
94 derive gType ?#, ?, ?^
95 derive gType [], [! ], [ !], [!!], [#], [#!], {}, {!}, {#}, {32#}
96 derive gType (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)