1 definition module GenType
4 from StdOverloaded import class ==, class toString
6 //* Auxiliary type to help with casting values, this is gone at runtime
11 reBox x :== box (unBox x)
13 //* Deeply embedded generic type representation
17 | GTyArrow GType GType
18 | GTyArray ArrayType GType
19 | GTyUList UListType GType
22 | GTyEither GType GType
24 | GTyCons GenericConsDescriptor GType
25 | GTyField GenericFieldDescriptor GType
26 | GTyObject GenericTypeDefDescriptor GType
27 | GTyRecord GenericRecordDescriptor GType
29 //* Type representation larded with the generic type information
34 | TyArray ArrayType Type
35 | TyUList UListType Type
37 | TyNewType GenericTypeDefDescriptor GenericConsDescriptor Type
38 | TyObject GenericTypeDefDescriptor [(GenericConsDescriptor, [Type])]
39 | TyRecord GenericRecordDescriptor [(GenericFieldDescriptor, Type)]
42 :: BasicType = BTInt | BTChar | BTReal | BTBool | BTDynamic | BTFile | BTWorld
44 :: ArrayType = AStrict | ALazy | AUnboxed | APacked
45 //* Unboxed list kinds
46 :: UListType = ULLazy | ULStrict
48 :: Kind = KStar | (KArrow) infixr 1 Kind Kind
50 instance == GType, Type, BasicType, ArrayType, UListType, GenType, Kind
51 instance toString GType, Type, BasicType, ArrayType, UListType, GenType, Kind
54 * Removes recursive types by replacing them with references
57 * @result the main type
58 * @result the separated types grouped in strongly connected components
60 flattenGType :: GType -> [[GType]]
62 //* Convert a GType to a Type
63 gTypeToType :: GType -> Type
65 //* Extract the name of the type
66 typeName :: Type -> String
68 //* Extract the genType for a type
69 typeGenType :: Type -> [GenType]
71 //* Extract the kind of the type's constructors (see `{{typeGenType}}`)
72 genTypeKind :: [GenType] -> Kind
73 //* @type Type -> Kind
74 typeKind t :== genTypeKind (typeGenType t)
76 //* Predicate whether the outer type is a builtin type
77 class isBuiltin a :: a -> Bool
78 instance isBuiltin Type, GType
80 //* Predicate whether the outer type is a basic type
81 class isBasic a :: a -> Bool
82 instance isBasic Type, GType
84 //* Replace builtin constructors with their pretty names (e.g. _!Cons with [!])
85 class replaceBuiltins a :: a -> a
86 instance replaceBuiltins Type, GType, GenType
88 //* Creates a deep embedded generic representation of a type
89 generic gType a :: Box GType a
90 derive gType UNIT, EITHER, PAIR, CONS of gcd, FIELD of gfd, OBJECT of gtd, RECORD of grd
91 derive gType Int, Bool, Real, Char, World, File
93 derive gType ?#, ?, ?^
94 derive gType [], [! ], [ !], [!!], [#], [#!], {}, {!}, {#}, {32#}
95 derive gType (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)