typesupport.icl 34.9 KB
Newer Older
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
1
2
3
4
5
implementation module typesupport

import StdEnv, StdCompare
import syntax, parse, check, unitype, utilities, RWSDebug

6
7
// MW: this switch is used to en(dis)able the fusion algorithm
SwitchFusion fuse dont_fuse :== fuse
8

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
::	Store	:== Int

::	AttrCoercion =
	{	ac_demanded	:: !Int
	,	ac_offered	:: !Int
	}

::	TempSymbolType =
	{	tst_args		:: ![AType]
	,	tst_arity		:: !Int
	,	tst_lifted		:: !Int
	,	tst_result		:: !AType
	,	tst_context		:: ![TypeContext]
	,	tst_attr_env	:: ![AttrCoercion]
	}


simplifyTypeApplication :: !Type ![AType] -> Type
simplifyTypeApplication (TA type_cons=:{type_arity} cons_args) type_args
	= TA { type_cons & type_arity = type_arity + length type_args } (cons_args ++ type_args)
simplifyTypeApplication (TV tv) type_args
	= CV tv :@: type_args
simplifyTypeApplication (CV tv :@: type_args1) type_args2
	= CV tv :@: (type_args1 ++ type_args2)

::	AttributeEnv	:== {! TypeAttribute }
::	VarEnv 			:== {! Type }

::	CleanUpState =
	{	cus_var_env		:: !.VarEnv
	,	cus_attr_env	:: !.AttributeEnv
	,	cus_heaps		:: !.TypeHeaps
	,	cus_var_store	:: !Int
	,	cus_attr_store	:: !Int
	,	cus_error		:: !.ErrorAdmin
	}

46
47
48
49
50
::	CleanUpInput =
	{	cui_coercions	:: !{! CoercionTree}
	,	cui_attr_part	:: !AttributePartition
	,	cui_top_level	:: !Bool
	}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
51

52
class clean_up a ::  !CleanUpInput !a !*CleanUpState -> (!a, !*CleanUpState)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
53
54
55

instance clean_up AType
where
56
57
58
	clean_up cui atype=:{at_attribute,at_type} cus
		# (at_attribute, cus) = clean_up cui at_attribute cus 
		  (at_type, cus) = clean_up cui at_type cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
59
60
61
62
63
64
65
66
67
68
		= ({atype & at_attribute = at_attribute, at_type = at_type}, cus)

attrIsUndefined TA_None = True
attrIsUndefined _ 		= False

varIsDefined TE		= False
varIsDefined _ 		= True

instance clean_up TypeAttribute
where
69
	clean_up cui TA_Unique cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
70
		= (TA_Unique, cus)
71
	clean_up cui TA_Multi cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
72
		= (TA_Multi, cus)
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
	clean_up cui tv=:(TA_TempVar av_number) cus=:{cus_attr_env,cus_heaps,cus_attr_store,cus_error}
		| cui.cui_top_level
			# av_group_nr = cui.cui_attr_part.[av_number]
			  coercion_tree = cui.cui_coercions.[av_group_nr]
			| isNonUnique coercion_tree
				= (TA_Multi, cus)
			| isUnique coercion_tree
				= (TA_Unique, cus)
			#! attr = cus_attr_env.[av_group_nr]
			| attrIsUndefined attr
				# (av_info_ptr, th_attrs) = newPtr AVI_Empty cus_heaps.th_attrs
				  new_attr_var = TA_Var { av_name = NewAttrVarId cus_attr_store, av_info_ptr = av_info_ptr }
				= (new_attr_var, { cus & cus_attr_env = { cus_attr_env & [av_group_nr] = new_attr_var},
						 cus_heaps = { cus_heaps & th_attrs = th_attrs }, cus_attr_store = inc cus_attr_store})
				= (attr, cus)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
88
			= (TA_Multi, cus)
89
			
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
90
91
instance clean_up Type
where
92
	clean_up cui (TempV tv_number) cus=:{cus_var_env}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
93
		#! type = cus_var_env.[tv_number]
94
95
96
		= cleanUpVariable cui.cui_top_level type tv_number cus
	clean_up cui (TA tc types) cus
		# (types, cus) = clean_up cui types cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
97
		= (TA tc types, cus)
98
99
100
	clean_up cui (argtype --> restype) cus
		# (argtype, cus) = clean_up cui argtype cus
		  (restype, cus) = clean_up cui restype cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
101
		=  (argtype --> restype, cus)
102
	clean_up cui t=:(TB _) cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
103
		=  (t, cus)
104
	clean_up cui (TempCV tempvar :@: types) cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
105
		#! type = cus.cus_var_env.[tempvar]
106
107
		# (type, cus) = cleanUpVariable cui.cui_top_level type tempvar cus
		  (types, cus) = clean_up cui types cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
108
		= (simplifyTypeApplication type types, cus)
109
	clean_up cui (TempQV qv_number) cus=:{cus_var_env,cus_error}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
110
		#! type = cus_var_env.[qv_number]
111
112
113
114
		| cui.cui_top_level
			= cleanUpVariable True type qv_number {cus & cus_error = existentialError cus_error}
			= cleanUpVariable False type qv_number cus
	clean_up cui TE cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
115
116
117
118
		= abort "unknown pattern in function clean_up"
				
instance clean_up [a] | clean_up a
where
119
	clean_up cui l cus = mapSt (clean_up cui) l cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
120

121
cleanUpVariable _ TE tv_number cus=:{cus_heaps,cus_var_store,cus_var_env}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
122
123
124
125
	# (tv_info_ptr, th_vars) = newPtr TVI_Empty cus_heaps.th_vars
	  new_var = TV { tv_name = NewVarId cus_var_store, tv_info_ptr = tv_info_ptr }
	= (new_var, { cus & cus_var_env = { cus_var_env & [tv_number] = new_var},
				cus_heaps = { cus_heaps & th_vars = th_vars }, cus_var_store = inc cus_var_store})
126
127
128
129
130
cleanUpVariable top_level (TLifted var) tv_number cus=:{cus_error}
	| top_level
		= (TV var, { cus & cus_error = liftedError var cus_error})
		= (TV var, cus)
cleanUpVariable _ type tv_number cus
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
	= (type, cus)

class cleanUpClosed a :: !a !u:VarEnv -> (!Bool, !a, !u:VarEnv)

instance cleanUpClosed AType
where
	cleanUpClosed atype=:{at_type} env
		# (ok, at_type, env) = cleanUpClosed at_type env
		= (ok, { atype & at_type = at_type}, env)

instance cleanUpClosed Type
where
	cleanUpClosed (TempV tv_number) env
		#! type = env.[tv_number]
		= (varIsDefined type, type, env)
	cleanUpClosed (TA tc types) env
		# (ok, types, env) = cleanUpClosed types env
		= (ok, TA tc types, env)
	cleanUpClosed (argtype --> restype) env
		# (ok, (argtype,res_type), env) = cleanUpClosed (argtype,restype) env
		= (ok, argtype --> restype, env)
	cleanUpClosed (TempCV tv_number :@: types) env
		#! type = env.[tv_number]
		| varIsDefined type
			# (ok, types, env) = cleanUpClosed types env
            = (ok, simplifyTypeApplication type types, env)
			= (False, TempCV tv_number :@: types, env)
	cleanUpClosed t env
		= (True, t, env)

instance cleanUpClosed (a,b) | cleanUpClosed a & cleanUpClosed b
where
	cleanUpClosed (x,y) env
		# (ok_x, x, env) = cleanUpClosed x env
		| ok_x
			# (ok_y, y, env) = cleanUpClosed y env
			= (ok_y, (x,y), env)
		= (False, (x,y), env)

instance cleanUpClosed [a] | cleanUpClosed a
where
	cleanUpClosed [] env
		= (True, [], env)
	cleanUpClosed [t:ts] env
		# (ok, (t,ts), env) = cleanUpClosed (t,ts) env
		= (ok, [t:ts], env)

178
179
180
181
182
errorHeading :: !String !*ErrorAdmin -> *ErrorAdmin
errorHeading  error_kind err=:{ea_file,ea_loc = []}
	= { err & ea_file = ea_file <<< error_kind <<< ':', ea_ok = False }
errorHeading  error_kind err=:{ea_file,ea_loc = [ loc : _ ]}
	= { err & ea_file = ea_file <<< error_kind <<< ' ' <<< loc <<< ':', ea_ok = False }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
183
184

overloadingError class_symb err
185
186
	# err = errorHeading "Type error" err
	= { err & ea_file = err.ea_file <<< "internal overloading of class " <<< class_symb <<< " is unsolvable\n" }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
187
188

existentialError err
189
190
	# err = errorHeading "Type error" err
	= { err & ea_file = err.ea_file <<< "existential type variable appears in the derived type specification\n" }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
191
192

liftedError var err
193
194
	# err = errorHeading "Type error" err
	= { err & ea_file = err.ea_file <<< "type variable of type of lifted argument " <<< var <<< " appears in the specified type\n" }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

clean_up_type_contexts [] env error
	= ([], env, error)
clean_up_type_contexts [tc:tcs] env error
	# (tcs, env, error) = clean_up_type_contexts tcs env error
	  (ok_tc_types, tc_types, env) = cleanUpClosed tc.tc_types env
	| ok_tc_types
		= ([{ tc & tc_types = tc_types } : tcs], env, error)
		= (tcs, env, overloadingError tc.tc_class.glob_object.ds_ident error)

extendSymbolType :: !SymbolType !Int !*TypeHeaps -> (!SymbolType, !*TypeHeaps)
extendSymbolType st=:{st_arity,st_args,st_vars,st_attr_vars} nr_of_extra_args type_heaps
	| nr_of_extra_args > 0
		# (st_args, (st_vars, st_attr_vars, type_heaps))
			= newAttributedVariables nr_of_extra_args st_args (st_vars, st_attr_vars, type_heaps)
		= ({ st & st_args = st_args, st_vars = st_vars, st_attr_vars = st_attr_vars, st_arity = st_arity + nr_of_extra_args }, type_heaps)
		= (st, type_heaps)

cleanSymbolType :: !Int !*TypeHeaps -> (!SymbolType, !*TypeHeaps)
cleanSymbolType arity type_heaps
	# (st_result, clean_state) = newAttributedVariable 0 ([], [], type_heaps)
	  (st_args, (st_vars, st_attr_vars, type_heaps)) = newAttributedVariables arity [] clean_state
	= ({ st_arity = arity, st_vars = st_vars , st_args = st_args, st_result = st_result, st_context = [],
			st_attr_env = [], st_attr_vars = st_attr_vars }, type_heaps)

newAttributedVariables var_number attributed_variables clean_state=:(_,_,_) /* Temporary hack */
	| var_number == 0
		= (attributed_variables, clean_state)
		# (attributed_variable, clean_state) = newAttributedVariable var_number clean_state
		= newAttributedVariables (dec var_number) [ attributed_variable : attributed_variables ] clean_state

newAttributedVariable var_number (variables, attributes, type_heaps=:{th_vars,th_attrs})
	# (tv_info_ptr, th_vars) = newPtr TVI_Empty th_vars
	  new_var = { tv_name = NewVarId var_number, tv_info_ptr = tv_info_ptr }
	  (av_info_ptr, th_attrs) = newPtr AVI_Empty th_attrs
	  new_attr_var = { av_name = NewAttrVarId var_number, av_info_ptr = av_info_ptr }
	= ({ at_annotation = AN_None, at_attribute = TA_Var new_attr_var, at_type = TV new_var},
		([ new_var : variables ], [ new_attr_var : attributes ], { type_heaps & th_vars = th_vars, th_attrs = th_attrs }))

234
235
236
237
238
cleanUpSymbolType :: !TempSymbolType ![TypeContext] ![ExprInfoPtr] !{! CoercionTree} !AttributePartition
						!*VarEnv !*AttributeEnv !*TypeHeaps !*ExpressionHeap !*ErrorAdmin
							-> (!SymbolType, !*VarEnv, !*AttributeEnv, !*TypeHeaps, !*ExpressionHeap, !*ErrorAdmin)
cleanUpSymbolType tst=:{tst_arity,tst_args,tst_result,tst_context,tst_lifted} context case_and_let_exprs
		coercions attr_part var_env attr_var_env heaps expr_heap error
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
239
240
241
242
	#! nr_of_temp_vars = size var_env
	#! max_attr_nr = size attr_var_env
	# cus = { cus_var_env = var_env, cus_attr_env = attr_var_env, cus_heaps = heaps,
			  cus_var_store = 0, cus_attr_store = 0, cus_error = error }
243
244
245
246
247
	  cui = { cui_coercions = coercions, cui_attr_part = attr_part, cui_top_level = True }
	  (lifted_args, cus=:{cus_var_env}) = clean_up cui (take tst_lifted tst_args) cus
	  (lifted_vars, cus_var_env) = determine_type_vars nr_of_temp_vars [] cus_var_env
	  (st_args, cus) = clean_up cui (drop tst_lifted tst_args) { cus & cus_var_env = cus_var_env }
	  (st_result, cus) = clean_up cui tst_result cus
248
249
	  (st_context, cus_var_env, cus_error) = clean_up_type_contexts (tst_context ++ context) cus.cus_var_env cus.cus_error
	  (st_vars, cus_var_env) = determine_type_vars nr_of_temp_vars lifted_vars cus_var_env
250
251
252
	  (cus_attr_env, st_attr_vars, st_attr_env) = build_attribute_environment 0 max_attr_nr coercions cus.cus_attr_env [] []
	  (expr_heap, {cus_var_env,cus_attr_env,cus_heaps,cus_error}) = update_expression_types { cui & cui_top_level = False } case_and_let_exprs
				expr_heap { cus & cus_var_env = cus_var_env, cus_attr_env = cus_attr_env, cus_error = cus_error }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
253
254
	  st = {  st_arity = tst_arity, st_vars = st_vars , st_args = lifted_args ++ st_args, st_result = st_result, st_context = st_context,
			st_attr_env = st_attr_env, st_attr_vars = st_attr_vars }
255
256
	= (st,			{ cus_var_env & [i] = TE \\ i <- [0..nr_of_temp_vars - 1]},
					{ cus_attr_env & [i] = TA_None \\ i <- [0..max_attr_nr - 1]}, cus_heaps, expr_heap, cus_error)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
257
where
258
259
260
261
262
263
264
265
266
267
268
	determine_type_vars to_index all_vars var_env
		= iFoldSt determine_type_var 0 to_index (all_vars, var_env)
	where
		determine_type_var var_index (all_vars, var_env)
			#! type = var_env.[var_index]
			= case type of
				TV var
					-> ([var : all_vars], { var_env & [var_index] = TLifted var})
				_
					-> (all_vars, var_env)

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
269

270
271
272
273
274
275
276
277
	determine_type_var var_index (all_vars, var_env)
		#! type = var_env.[var_index]
		= case type of
			TV var
				-> ([var : all_vars], var_env)
			_
				-> (all_vars, var_env)

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
	
	build_attribute_environment :: !Index !Index !{! CoercionTree} !*AttributeEnv ![AttributeVar] ![AttrInequality]
		-> (!*AttributeEnv, ![AttributeVar], ![AttrInequality])
	build_attribute_environment attr_group_index max_attr_nr coercions attr_env attr_vars inequalities
		| attr_group_index == max_attr_nr
			= (attr_env, attr_vars, inequalities)
		#! attr = attr_env.[attr_group_index]
		= case attr of
			TA_Var attr_var
				# (attr_env, inequalities) = build_inequalities attr_var coercions.[attr_group_index] coercions attr_env inequalities
				-> build_attribute_environment (inc attr_group_index) max_attr_nr coercions attr_env [attr_var : attr_vars] inequalities
			TA_None
				-> build_attribute_environment (inc attr_group_index) max_attr_nr coercions attr_env attr_vars inequalities
	
	build_inequalities off_var (CT_Node dem_attr left right) coercions attr_env inequalities
		# (attr_env, inequalities) = build_inequalities off_var left coercions attr_env inequalities
		  (attr_env, inequalities) = build_inequalities off_var right coercions attr_env inequalities
		#! attr = attr_env.[dem_attr]
		= case attr of
			TA_Var attr_var
				| is_new_inequality attr_var off_var inequalities
					-> (attr_env, [{ ai_demanded = attr_var, ai_offered = off_var } : inequalities]) 
					-> (attr_env, inequalities)
			TA_None
				-> build_inequalities off_var coercions.[dem_attr] coercions attr_env inequalities
	build_inequalities off_var tree coercions attr_env inequalities
		= (attr_env, inequalities)

	is_new_inequality dem_var off_var []
		= True
	is_new_inequality dem_var off_var [{ ai_demanded, ai_offered } : inequalities]
		= (dem_var <> ai_demanded || off_var <> ai_offered) && is_new_inequality dem_var off_var inequalities

311
312
	update_expression_types :: !CleanUpInput ![ExprInfoPtr] !*ExpressionHeap !*CleanUpState -> (!*ExpressionHeap,!*CleanUpState);
	update_expression_types cui expr_ptrs expr_heap cus
313
314
		= (expr_heap, cus)
//		= foldSt (update_expression_type cui) expr_ptrs (expr_heap, cus)
315

316
	update_expression_type cui expr_ptr (expr_heap, cus)
317
318
319
		# (info, expr_heap) = readPtr expr_ptr expr_heap
		= case info of
			EI_CaseType case_type
320
				# (case_type, cus) = clean_up cui case_type cus
321
322
				-> (expr_heap <:= (expr_ptr, EI_CaseType case_type), cus)
			EI_LetType let_type
323
				# (let_type, cus) = clean_up cui let_type cus
324
325
326
327
				-> (expr_heap <:= (expr_ptr, EI_LetType let_type), cus)

instance clean_up CaseType
where
328
329
330
331
	clean_up cui ctype=:{ct_pattern_type,ct_result_type, ct_cons_types} cus
		# (ct_pattern_type, cus) = clean_up cui ct_pattern_type cus 
		  (ct_result_type, cus) = clean_up cui ct_result_type cus
		  (ct_cons_types, cus) = clean_up cui ct_cons_types cus
332
		= ({ctype & ct_pattern_type = ct_pattern_type, ct_cons_types = ct_cons_types, ct_result_type = ct_result_type}, cus)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
333

334
335
336
337
338
339
/*
	In 'bindInstances t1 t2' type variables of t1 are bound to the corresponding subtypes of t2, provided that
	t2 is a substitution instance of t1. Binding is done by setting the 'tv_info_ptr' of the variables of t1
	to 'TVI_Type t' were t is the subtype to which the type variable is matched.
	Be careful with calling 'bindInstances': all the 'tv_info_ptr'-info's should be cleaned first, unless one 
	is sure that t1 does not contain any 'tv_info_ptr' with value  'TVI_Type ...'.
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
340
	
341

342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
	instance bindInstances AType, Type, [a] | bindInstances a
*/ 

updateExpressionTypes :: !SymbolType !SymbolType ![ExprInfoPtr] !*TypeHeaps !*ExpressionHeap -> (!*TypeHeaps, !*ExpressionHeap)
updateExpressionTypes {st_args,st_vars,st_result,st_attr_vars} st_copy case_and_let_exprs heaps=:{th_vars,th_attrs} expr_heap
	# th_vars = foldSt (\{tv_info_ptr} var_heap -> var_heap <:= (tv_info_ptr, TVI_Empty)) st_vars th_vars
	  th_attrs = foldSt (\{av_info_ptr} attr_heap -> attr_heap <:= (av_info_ptr, AVI_Empty)) st_attr_vars th_attrs
	  th_vars = bindInstances st_args st_copy.st_args th_vars
	  th_vars = bindInstances st_result st_copy.st_result th_vars
	= foldSt update_expression_type case_and_let_exprs ({heaps & th_vars = th_vars, th_attrs = th_attrs}, expr_heap)
where
	update_expression_type expr_ptr (type_heaps, expr_heap)
		# (info, expr_heap) = readPtr expr_ptr expr_heap
		= case info of
			EI_CaseType case_type
				# (case_type, type_heaps) = substitute case_type type_heaps
				-> (type_heaps, expr_heap <:= (expr_ptr, EI_CaseType case_type))
			EI_LetType let_type
				# (let_type, type_heaps) = substitute let_type type_heaps
				-> (type_heaps, expr_heap <:= (expr_ptr, EI_LetType let_type))


class bindInstances a :: !a !a !*TypeVarHeap -> *TypeVarHeap

instance bindInstances Type
367
  where
368
369
370
371
	bindInstances (TV {tv_info_ptr}) type type_var_heap
		# (tv_info, type_var_heap) = readPtr tv_info_ptr type_var_heap
		= case tv_info of
			TVI_Type ind_type
372
				-> type_var_heap
373
374
375
376
377
378
379
			_
				-> type_var_heap <:= (tv_info_ptr, TVI_Type type)
	bindInstances (TA _ arg_types1) (TA _ arg_types2) type_var_heap
		= bindInstances arg_types1 arg_types2 type_var_heap
	bindInstances (l1 --> r1) (l2 --> r2) type_var_heap
		= bindInstances r1 r2 (bindInstances l1 l2 type_var_heap)
	bindInstances (TB _) (TB _) type_var_heap
380
		= type_var_heap
Sjaak Smetsers's avatar
Sjaak Smetsers committed
381
	bindInstances (CV l1 :@: r1) (CV l2 :@: r2) type_var_heap
382
		= bindInstances r1 r2 (bindInstances (TV l1) (TV l2) type_var_heap)
383
384
	bindInstances a b  tvh
		= abort ("abort"--->(a,b))
385

386
instance bindInstances [a] | bindInstances a
387
  where
388
	bindInstances [] [] type_var_heap
389
		= type_var_heap
390
391
	bindInstances [x:xs] [y:ys] type_var_heap
		= bindInstances xs ys (bindInstances x y type_var_heap)
392
	
393
instance bindInstances AType
394
  where
395
396
	bindInstances {at_type=t1} {at_type=t2} type_var_heap
			= bindInstances t1 t2 type_var_heap
397
398


399
class substitute a :: !a !*TypeHeaps -> (!a, !*TypeHeaps)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
400
401
402
403
404
405
406
407
408
409

instance substitute AType
where
	substitute atype=:{at_attribute,at_type} heaps
		# ((at_attribute,at_type), heaps)  = substitute (at_attribute,at_type) heaps
		= ({ atype & at_attribute = at_attribute, at_type = at_type }, heaps)

instance substitute TypeAttribute
where
	substitute (TA_Var {av_name, av_info_ptr}) heaps=:{th_attrs}
410
411
412
/* 
	This alternative's code can be replaced with the original again, when the fusion algorithm becomes able to
    infer correct type attributes
413
414
415
*/
		#! av_info = sreadPtr av_info_ptr th_attrs
		= case av_info of
416
417
418
419
420
421
			AVI_Attr attr
				-> (attr, heaps)
			_
				-> SwitchFusion
						(TA_Multi, heaps)
						(abort "compiler bug nr 7689 in module typesupport")
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
	substitute TA_None heaps
		= (TA_Multi, heaps)
	substitute attr heaps
		= (attr, heaps)

instance substitute (a,b) | substitute a & substitute b
where
	substitute (x,y) heaps
		# (x, heaps) = substitute x heaps
		  (y, heaps) = substitute y heaps
		= ((x,y), heaps)
	
instance substitute [a] | substitute a
where
	substitute [] heaps
		= ([], heaps)
	substitute [t:ts] heaps
		# (t, heaps) = substitute t heaps
		  (ts, heaps) = substitute ts heaps
		= ([t:ts], heaps)


instance substitute TypeContext
where
	substitute tc=:{tc_types} heaps
		# (tc_types, heaps) = substitute tc_types heaps
		= ({ tc & tc_types = tc_types }, heaps)

450
451
452
substituteTypeVariable tv=:{tv_name,tv_info_ptr} heaps=:{th_vars}
	# (tv_info, th_vars) = readPtr tv_info_ptr th_vars
	  heaps = { heaps & th_vars = th_vars }
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
453
454
455
456
	= case tv_info of
		TVI_Type type
			-> (type, heaps)
		_
457
			-> (TV tv, heaps)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

instance substitute Type
where
	substitute (TV tv) heaps
		= substituteTypeVariable tv heaps
	substitute (arg_type --> res_type)  heaps
		# ((arg_type, res_type), heaps) = substitute (arg_type, res_type) heaps
		= (arg_type --> res_type, heaps)
	substitute (TA cons_id cons_args)  heaps
		# (cons_args, heaps) = substitute cons_args heaps
		= (TA cons_id cons_args,  heaps)
	substitute (CV type_var :@: types)  heaps
		# (type, heaps) = substituteTypeVariable type_var heaps
		  (types, heaps) = substitute types heaps
		= (simplifyTypeApplication type types, heaps)
	substitute type heaps
		= (type, heaps)

instance substitute AttributeVar
where
478
	substitute av=:{av_info_ptr} heaps=:{th_attrs}
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
479
		#! av_info = sreadPtr av_info_ptr th_attrs
480
481
482
483
484
		= case av_info of
			AVI_Attr (TA_Var attr_var)
				-> (attr_var, heaps)
			_
				-> (av, heaps)
Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
485
486
487
488
489
490
491

instance substitute AttrInequality
where
	substitute {ai_demanded,ai_offered} heaps
		# ((ai_demanded, ai_offered), heaps) = substitute (ai_demanded, ai_offered) heaps
		= ({ai_demanded = ai_demanded, ai_offered = ai_offered}, heaps)

492
493
494
495
496
497
498
499
instance substitute CaseType
where
	substitute {ct_pattern_type, ct_result_type, ct_cons_types} heaps 
		# (ct_pattern_type, heaps) = substitute ct_pattern_type heaps
		  (ct_result_type, heaps) = substitute ct_result_type heaps
		  (ct_cons_types, heaps) = substitute ct_cons_types heaps
		= ({ct_pattern_type = ct_pattern_type, ct_result_type = ct_result_type, ct_cons_types = ct_cons_types}, heaps)

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
expandTypeApplication :: ![ATypeVar] !TypeAttribute !Type ![AType] !TypeAttribute !*TypeHeaps -> (!Type, !*TypeHeaps)
expandTypeApplication type_args form_attr type_rhs arg_types act_attr type_heaps=:{th_attrs}
	# th_attrs = bind_attr form_attr act_attr th_attrs 
	= substitute type_rhs (fold2St bind_type_and_attr type_args arg_types { type_heaps & th_attrs = th_attrs })
where
	bind_type_and_attr {atv_attribute = TA_Var {av_name,av_info_ptr}, atv_variable={tv_info_ptr}} {at_attribute,at_type} {th_vars,th_attrs}
		= { th_vars = th_vars <:= (tv_info_ptr, TVI_Type at_type), th_attrs = th_attrs <:= (av_info_ptr, AVI_Attr at_attribute) }
	bind_type_and_attr {atv_variable={tv_info_ptr}} {at_type} type_heaps=:{th_vars}
		= { type_heaps & th_vars = th_vars <:= (tv_info_ptr, TVI_Type at_type) }

	bind_attr (TA_Var {av_name,av_info_ptr}) attr th_attrs
		= th_attrs <:= (av_info_ptr, AVI_Attr attr) 
	bind_attr _ attr th_attrs
		= th_attrs
		

VarIdTable :: {# String}
VarIdTable =: { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }

newIdent id_name
	:== { id_name = id_name, id_info = nilPtr }
	
NewVarId var_store
	| var_store < size VarIdTable
		= newIdent VarIdTable.[var_store]
		= newIdent ("v" +++ toString var_store)
 
AttrVarIdTable :: {# String}
AttrVarIdTable =: { "u", "v", "w", "x", "y", "z" }

NewAttrVarId attr_var_store
	| attr_var_store < size AttrVarIdTable
 		= newIdent AttrVarIdTable.[attr_var_store]
		= newIdent ("u" +++ toString attr_var_store)



instance == AttributeVar
where
	(==) av1 av2 = av1.av_info_ptr == av2.av_info_ptr 



class equiv a :: !a !a !*TypeHeaps -> (!Bool, !*TypeHeaps)

instance equiv AType
where
	equiv atype1 atype2 heaps=:{th_attrs}
		# (ok, th_attrs) = equi_attrs atype1.at_attribute atype2.at_attribute th_attrs
		| ok
			= equiv atype1.at_type atype2.at_type { heaps & th_attrs = th_attrs }
			= (False, { heaps & th_attrs = th_attrs })

	where
		equi_attrs attr=:(TA_Var {av_info_ptr}) (TA_TempVar av_number) attr_var_heap
			#! av_info = sreadPtr av_info_ptr attr_var_heap
			= case av_info of
				AVI_Forward forw_var_number
					-> (forw_var_number == av_number, attr_var_heap)
				_
					-> (True, writePtr av_info_ptr (AVI_Forward av_number) attr_var_heap)
		equi_attrs attr1 attr2 attr_env
			= (attr1 == attr2, attr_env)

equivTypeVars :: !TypeVar !TempVarId !*TypeHeaps -> (!Bool, !*TypeHeaps)
equivTypeVars {tv_info_ptr} var_number heaps=:{th_vars}
	#! tv_info = sreadPtr tv_info_ptr th_vars
	= case tv_info of
		TVI_Forward forw_var_number
			-> (forw_var_number == var_number, heaps)
		_
			-> (True, { heaps & th_vars = writePtr tv_info_ptr (TVI_Forward var_number) heaps.th_vars })
	

instance equiv Type
where
	equiv (TV tv) (TempV var_number) heaps
		= equivTypeVars tv var_number heaps
	equiv (arg_type1 --> restype1) (arg_type2 --> restype2) heaps
		= equiv (arg_type1,restype1) (arg_type2,restype2) heaps
	equiv (TA tc1 types1) (TA tc2 types2) heaps
		| tc1 == tc2
			= equiv types1 types2 heaps
			= (False, heaps)
	equiv (TB basic1) (TB basic2) heaps
		= (basic1 == basic2, heaps)
	equiv (CV tv :@: types1) (TempCV var_number :@: types2) heaps
		# (equi_vars, heaps) =  equivTypeVars tv var_number heaps
		| equi_vars
			= equiv types1 types2 heaps
			= (False, heaps)
/*	equiv (TFA vars type1) type2 heaps
		= equiv type1 type2 heaps
	equiv type1 (TFA vars type2) heaps
		= equiv type1 type2 heaps
	equiv (TQV _) (TV _) heaps
		= (True, heaps)
*/
	equiv type1 type2 heaps
		= (False, heaps)

instance equiv (a,b) | equiv a & equiv b
where
	equiv (x1,y1) (x2,y2) heaps
		# (equi_x, heaps) =  equiv x1 x2 heaps
		| equi_x
			= equiv y1 y2 heaps
			= (False, heaps)

instance equiv [a] | equiv a
where
	equiv [x:xs] [y:ys] heaps
		# (equi, heaps) = equiv x y heaps
		| equi
		  	= equiv xs ys heaps
			= (False, heaps)
	equiv [] [] heaps
		= (True, heaps)
	equiv _ _ heaps
		= (False, heaps)

equivalent :: !SymbolType  !TempSymbolType !{# CommonDefs}  !*AttributeEnv !*TypeHeaps -> (!Bool, !*AttributeEnv, !*TypeHeaps) 
equivalent {st_args,st_result,st_context,st_attr_env} {tst_args,tst_result,tst_context,tst_attr_env,tst_lifted} defs attr_env heaps
	#! nr_of_temp_attrs = size attr_env
	# (ok, heaps) = equiv (drop tst_lifted st_args,st_result) (drop tst_lifted tst_args,tst_result) heaps
	| ok
		# (ok, heaps) = equivalent_list_of_contexts st_context tst_context defs heaps
		| ok
			# (ok, attr_env, attr_var_heap) = equivalent_environments st_attr_env (fill_environment tst_attr_env attr_env) heaps.th_attrs
			= (ok, clear_environment tst_attr_env attr_env, { heaps & th_attrs = attr_var_heap })
			= (False, attr_env, heaps)
		= (False, attr_env, heaps)
where
	equivalent_list_of_contexts [] contexts defs heaps 
		= (True, heaps)
	equivalent_list_of_contexts [tc : tcs] contexts defs heaps 
		# (ok, heaps) = contains_context tc contexts defs heaps
		| ok
			= equivalent_list_of_contexts tcs contexts defs heaps
			= (False, heaps)

	contains_context tc1 [tc2 : tcs] defs heaps
		# (ok, heaps) = equivalent_contexts tc1 tc2 defs heaps
		| ok
			= (True, heaps)
			= contains_context tc1 tcs defs heaps
	contains_context tc1 [] defs heaps
		= (False, heaps)
	
	equivalent_contexts tc {tc_class,tc_types} defs heaps
		| tc_class == tc.tc_class
			= equiv tc.tc_types tc_types heaps
		# {glob_object={ds_index},glob_module} = tc_class
		#! class_def = defs.[glob_module].com_class_defs.[ds_index]
		# {class_context,class_args} = class_def
		| isEmpty class_context
			= (False, heaps)
		# th_vars = bind_class_args class_args tc_types heaps.th_vars
		= equivalent_superclasses class_context tc defs { heaps & th_vars = th_vars }
	where	
		bind_class_args [{tv_info_ptr} : vars] [type : types] type_var_heap
			= bind_class_args vars types (writePtr tv_info_ptr (TVI_Type type) type_var_heap)
		bind_class_args [] [] type_var_heap
			= type_var_heap
	
		equivalent_superclasses [] tc defs heaps
			= (False, heaps)
		equivalent_superclasses [super_tc=:{tc_types} : tcs] tc defs heaps=:{th_vars}
			# (tc_types, th_vars) = retrieve_types tc_types th_vars
			  (ok, heaps) = equivalent_contexts { super_tc & tc_types = tc_types } tc defs { heaps & th_vars = th_vars }
			| ok
				= (True, heaps)
				= equivalent_superclasses tcs tc defs heaps
		where
			retrieve_types [TV {tv_info_ptr} : types] type_var_heap
				#! (tv_info, type_var_heap) = readPtr tv_info_ptr type_var_heap
				#  (TVI_Type type) = tv_info
				#! (types, type_var_heap) = retrieve_types types type_var_heap
				= ([type : types], type_var_heap)
			retrieve_types [type : types] type_var_heap
				#! (types, type_var_heap) = retrieve_types types type_var_heap
				= ([type : types], type_var_heap)
			retrieve_types [] type_var_heap
				= ([], type_var_heap)
		

	fill_environment :: ![AttrCoercion] !*{! TypeAttribute} -> *{! TypeAttribute}
	fill_environment [] attr_env
		= attr_env
	fill_environment [{ac_demanded,ac_offered} : coercions ] attr_env
		#! offered = attr_env.[ac_demanded]
		=  fill_environment coercions { attr_env & [ac_demanded] = TA_List ac_offered offered }

	clear_environment :: ![AttrCoercion] !*{! TypeAttribute} -> *{! TypeAttribute}
	clear_environment [] attr_env
		= attr_env
	clear_environment [{ac_demanded,ac_offered} : coercions ] attr_env
		= clear_environment coercions { attr_env & [ac_demanded] = TA_None }
	
	equivalent_environments :: ![AttrInequality] !u:{!TypeAttribute} !v:AttrVarHeap -> (!Bool, !u:{!TypeAttribute}, !v:AttrVarHeap)
	equivalent_environments [] attr_env attr_heap
		= (True, attr_env, attr_heap)
	equivalent_environments [{ai_demanded,ai_offered} : coercions ] attr_env attr_heap
		#! av_info = sreadPtr ai_demanded.av_info_ptr attr_heap
		# (AVI_Forward demanded_var_number) = av_info
		#! av_info = sreadPtr ai_offered.av_info_ptr attr_heap
		# (AVI_Forward offered_var_number) = av_info
		#! offered_of_demanded = attr_env.[demanded_var_number]
		# (succ, attr_env) = contains_coercion offered_var_number offered_of_demanded attr_env
		| succ
			= equivalent_environments coercions attr_env attr_heap
			= (False, attr_env, attr_heap)

	contains_coercion :: !Int !TypeAttribute !u:{! TypeAttribute} -> (!Bool,!u:{!TypeAttribute});
	contains_coercion offered TA_None attr_env
		= (False, attr_env)
	contains_coercion offered (TA_List this_offered next_offered) attr_env
		| offered == this_offered
			= (True, attr_env)
		#! offered_of_offered = attr_env.[this_offered]
		# (succ, attr_env) = contains_coercion offered offered_of_offered attr_env
		| succ
			= (True, attr_env)
			= contains_coercion offered next_offered attr_env

725
:: Format =
726
727
	{	form_properties 	:: !BITVECT
	,	form_attr_position	:: Optional ([Int], Coercions)
728
729
730
	}

cNoProperties		:== 0
731
732
733
734
735
736
737
cAttributed			:== 1
cAnnotated			:== 2
cMarkAttribute		:== 4

cBrackets			:== 8
cCommaSeparator		:== 16
cArrowSeparator		:== 32
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754

checkProperty	form property	:== not (form.form_properties bitand property == 0)
setProperty		form property	:== {form & form_properties = form.form_properties bitor property}
clearProperty	form property	:== {form & form_properties = form.form_properties bitand (bitnot property)}

class (<::) infixl a :: !*File (!Format, !a) -> *File

instance <:: SymbolType
where
	(<::) file (form, {st_args, st_arity, st_result, st_context, st_attr_env})
		| st_arity > 0
			= show_environment form (show_context form (file <:: (form, st_args) <<< " -> " <:: (form, st_result)) st_context) st_attr_env
			= show_environment form ((show_context form (file <:: (form, st_result))) st_context) st_attr_env
	where
		show_context form file []
			= file
		show_context form file contexts
755
			= file <<<  " | " <:: (setProperty form cCommaSeparator, contexts)
756
757
758
759
	
		show_environment form file []
			= file
		show_environment form file environ
760
			= file <<<  ", " <:: (setProperty form cCommaSeparator, environ)
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783

instance <:: TypeContext
where
	(<::) file (form, {tc_class={glob_object={ds_ident}}, tc_types})
		= file <<< ds_ident <<< ' ' <:: (form, tc_types)

instance <:: AttrInequality
where
	(<::) file (form, {ai_demanded, ai_offered})
		= file <<< ai_offered <<< " <= " <<< ai_demanded

instance <:: AType
where
	(<::) file (form, {at_attribute, at_annotation, at_type})
		| checkProperty form cAnnotated
			= show_attributed_type (file <<< at_annotation) form at_attribute at_type
			= show_attributed_type file form at_attribute at_type
	where
		show_attributed_type file form TA_Multi type
			= file <:: (form, type) 
		show_attributed_type file form attr type
			| checkProperty form cAttributed
				= file <<< attr <:: (setProperty form cBrackets, type)
784
785
			| checkProperty form cMarkAttribute
				= show_marked_attribute attr form file <:: (setProperty form cBrackets, type)
786
787
				= file <:: (form, type)

788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
		show_marked_attribute attr {form_attr_position = Yes (positions, coercions)} file
			| isEmpty positions
				= show_attribute attr coercions (file <<< "^ ") 
				= show_attribute attr coercions file 

		show_attribute TA_Unique coercions file 
			= file <<< '*' 
		show_attribute TA_Multi coercions file 
			= file 
		show_attribute (TA_TempVar av_number) coercions file 
			| isUniqueAttribute av_number coercions
				= file <<< '*' 
			| isNonUniqueAttribute av_number coercions
				= file 
				= file <<< '.' 

804
805
806
807
808
809
810
811
812
instance <:: Type
where
	(<::) file (form, TV varid)
		= file <<< varid
	(<::) file (form, TempV tv_number)
		= file  <<< 'v' <<< tv_number
	(<::) file (form, TA {type_name,type_index,type_arity} types)
		| is_predefined type_index
			| is_list type_name
813
				= file <<< '[' <:: (setProperty form cCommaSeparator, types) <<< ']'
814
			| is_lazy_array type_name
815
				= file <<< '{' <:: (setProperty form cCommaSeparator, types) <<< '}'
816
			| is_strict_array type_name
817
				= file <<< "{!" <:: (setProperty form cCommaSeparator, types) <<< '}'
818
			| is_unboxed_array type_name
819
				= file <<< "{#" <:: (setProperty form cCommaSeparator, types) <<< '}'
820
			| is_tuple type_name type_arity
821
822
823
824
				= file <<< '(' <:: (setProperty form cCommaSeparator, types) <<< ')'
			| type_arity == 0
				= file <<< type_name
			| checkProperty form cBrackets
825
826
				= file <<< '(' <<< type_name <<< ' ' <:: (form, types) <<< ')'
				= file <<< type_name <<< ' ' <:: (setProperty form cBrackets, types)
827
828
829
		| type_arity == 0
			= file <<< type_name
		| checkProperty form cBrackets
830
831
832
833
834
835
836
837
838
839
840
841
842
			= file <<< '(' <<< type_name <<< ' ' <:: (form, types) <<< ')'
			= file <<< type_name <<< ' ' <:: (setProperty form cBrackets, types)
	where
			is_predefined {glob_module} 	= glob_module == cPredefinedModuleIndex

			is_list {id_name}				= id_name == "_list"
			is_tuple {id_name} tup_arity	= id_name == "_tuple" +++ toString tup_arity
			is_lazy_array {id_name} 		= id_name == "_array"
			is_strict_array {id_name} 		= id_name == "_!array"
			is_unboxed_array {id_name} 		= id_name == "_#array"

	(<::) file (form, arg_type --> res_type)
		| checkProperty form cBrackets
843
844
			= file  <<< '(' <:: (clearProperty (setProperty form cArrowSeparator) cBrackets, [arg_type, res_type])  <<< ')'
			= file  <:: (setProperty form (cBrackets bitor cArrowSeparator), [arg_type, res_type])
845
846
847
848
849
850
851
852
853
854
855
856
857
	(<::) file (form, type :@: types)
		| checkProperty form cBrackets
			= file <<< '(' <<< type <<< ' ' <:: (form, types)  <<< ')'
			= file <<< type <<< ' ' <:: (setProperty form cBrackets, types) 
	(<::) file (form, TB tb)
		= file <<< tb
	(<::) file (form, TQV varid)
		= file <<< "E." <<< varid
	(<::) file (form, TempQV tv_number)
		= file  <<< "E." <<< tv_number <<< ' ' 
	(<::) file (form, TE)
		= file <<< "__"

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

cNoPosition :== -1
	 
instance <:: [a] | <:: a
where
	(<::) file (form, types)
		= show_list 0 form types file
	where
		show_list elem_number form [type] file
			| checkProperty form cCommaSeparator
				= show_elem elem_number (clearProperty form cCommaSeparator) type file
			| checkProperty form cArrowSeparator
				= show_elem elem_number (clearProperty form cArrowSeparator) type file
				= show_elem elem_number (setProperty form cBrackets) type file
		show_list elem_number form [type : types] file
			| checkProperty form cCommaSeparator
				= show_list (inc elem_number) form types (show_elem elem_number (clearProperty form cCommaSeparator) type file <<< ',')
			| checkProperty form cArrowSeparator
				= show_list (inc elem_number) form types (show_elem elem_number (clearProperty form cArrowSeparator) type file <<< " -> ")
				= show_list (inc elem_number) form types (show_elem elem_number (setProperty form cBrackets) type file <<< ' ')
		show_list elem_number form [] file
			= file

		show_elem elem_nr form=:{form_attr_position = No} type file
			= file <:: (form, type)
		show_elem elem_nr form=:{form_attr_position = Yes ([pos : positions], coercions)} type file
			| elem_nr == pos
				= file <:: ({form & form_attr_position = Yes (positions, coercions)}, type)
			| pos == cNoPosition
				= file <:: (form, type)
				= file <:: ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type)
		show_elem elem_nr form=:{form_attr_position = Yes ([], coercions)} type file
			= file <:: ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type)

892
893
894
895
896
897
898

from compare_constructor import equal_constructor	

instance == Format
where
	(==) form1 form2 = equal_constructor form1 form2

Ronny Wichers Schreur's avatar
Ronny Wichers Schreur committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
instance <<< TypeContext
where
	(<<<) file tc = file <<< tc.tc_class.glob_object.ds_ident <<< ' ' <<< tc.tc_types

instance <<< AttrCoercion
where
	(<<<) file {ac_demanded,ac_offered} = file <<< ac_demanded <<< " <= " <<< ac_offered
	
instance <<< TempSymbolType
where
	(<<<) file {tst_args, tst_result, tst_context, tst_attr_env }
		| isEmpty tst_args
			= file <<< tst_result <<< " | " <<< tst_context <<< " [" <<< tst_attr_env <<< ']'
			= file <<< tst_args <<< " -> " <<< tst_result <<< " | " <<< tst_context <<< " [" <<< tst_attr_env <<< ']'