@@ -30,19 +30,19 @@ impl Module<Id> {
30
30
31
31
#[ deriving( Clone , PartialEq ) ]
32
32
pub struct Class < Ident > {
33
- pub constraints : ~[ Constraint ] ,
34
- pub name : InternedStr ,
33
+ pub constraints : ~[ Constraint < Name > ] ,
34
+ pub name : Name ,
35
35
pub variable : TypeVariable ,
36
- pub declarations : ~[ module:: TypeDeclaration ] ,
36
+ pub declarations : ~[ module:: TypeDeclaration < Name > ] ,
37
37
pub bindings : ~[ Binding < Ident > ]
38
38
}
39
39
40
40
#[ deriving( Clone ) ]
41
41
pub struct Instance < Ident = InternedStr > {
42
42
pub bindings : ~[ Binding < Ident > ] ,
43
- pub constraints : ~[ Constraint ] ,
43
+ pub constraints : ~[ Constraint < Name > ] ,
44
44
pub typ : Type ,
45
- pub classname : InternedStr
45
+ pub classname : Name
46
46
}
47
47
48
48
#[ deriving( Clone , PartialEq ) ]
@@ -165,7 +165,7 @@ impl <'a> Equiv<&'a str> for Name {
165
165
#[ deriving( PartialEq , Eq , Hash , Clone ) ]
166
166
pub struct Id < T = Name > {
167
167
pub name : T ,
168
- pub typ : Qualified < Type >
168
+ pub typ : Qualified < Type , Name >
169
169
}
170
170
171
171
impl fmt:: Show for Id {
@@ -175,7 +175,7 @@ impl fmt::Show for Id {
175
175
}
176
176
177
177
impl < T > Id < T > {
178
- pub fn new ( name : T , typ : Type , constraints : ~[ Constraint ] ) -> Id < T > {
178
+ pub fn new ( name : T , typ : Type , constraints : ~[ Constraint < Name > ] ) -> Id < T > {
179
179
Id { name : name, typ : module:: qualified ( constraints, typ) }
180
180
}
181
181
}
@@ -392,7 +392,7 @@ pub mod translate {
392
392
393
393
struct Translator < ' a > {
394
394
name_supply : NameSupply ,
395
- functions_in_class: |InternedStr |: ' a -> ( & ' a TypeVariable , & ' a [ TypeDeclaration ] )
395
+ functions_in_class: |Name |: ' a -> ( & ' a TypeVariable , & ' a [ TypeDeclaration < Name > ] )
396
396
}
397
397
398
398
#[ deriving( Show ) ]
@@ -490,7 +490,7 @@ pub mod translate {
490
490
}
491
491
492
492
///Creates stub functions for each undeclared function in the instance
493
- fn create_default_stubs ( class_var : & TypeVariable , class_decls : & [ TypeDeclaration ] , instance : & Instance < Id < Name > > ) -> Vec < Binding < Id < Name > > > {
493
+ fn create_default_stubs ( class_var : & TypeVariable , class_decls : & [ TypeDeclaration < Name > ] , instance : & Instance < Id < Name > > ) -> Vec < Binding < Id < Name > > > {
494
494
class_decls. iter ( )
495
495
. filter ( |decl| instance. bindings . iter ( ) . find ( |bind| bind. name . as_slice ( ) . ends_with ( decl. name . as_slice ( ) ) ) . is_none ( ) )
496
496
. map ( |decl| {
@@ -500,18 +500,17 @@ pub mod translate {
500
500
let mut typ = decl. typ . clone ( ) ;
501
501
:: typecheck:: replace_var ( & mut typ. value , class_var, & instance. typ ) ;
502
502
{
503
- let mut context = ~[ ] ;
504
- :: std:: mem:: swap ( & mut context, & mut typ. constraints ) ;
503
+ let context = :: std:: mem:: replace ( & mut typ. constraints , box [ ] ) ;
505
504
//Remove all constraints which refer to the class's variable
506
- let vec_context: Vec < Constraint > = context. move_iter ( )
505
+ let vec_context: Vec < Constraint < Name > > = context. move_iter ( )
507
506
. filter ( |c| c. variables [ 0 ] != * class_var)
508
507
. collect ( ) ;
509
508
typ. constraints = FromVec :: from_vec ( vec_context) ;
510
509
}
511
510
let Qualified { value : typ, constraints : constraints } = typ;
512
- let default_name = module:: encode_binding_identifier ( instance. classname , decl. name ) ;
511
+ let default_name = module:: encode_binding_identifier ( instance. classname . name , decl. name . name ) ;
513
512
let typ_name = module:: extract_applied_type ( & instance. typ ) . ctor ( ) . name ;
514
- let instance_fn_name = module:: encode_binding_identifier ( typ_name, decl. name ) ;
513
+ let instance_fn_name = module:: encode_binding_identifier ( typ_name, decl. name . name ) ;
515
514
516
515
//Example stub for undeclared (/=)
517
516
//(/=) = #Eq/=
@@ -623,7 +622,7 @@ impl <'a> Translator<'a> {
623
622
fn do_bind2_id ( & mut self , m_a : Type , m_b : Type ) -> Expr < Id < Name > > {
624
623
debug ! ( "m_a {}" , m_a) ;
625
624
let c = match * m_a. appl ( ) {
626
- TypeVariable ( ref var) => ~[ Constraint { class : intern ( "Monad" ) , variables : ~[ var. clone ( ) ] } ] ,
625
+ TypeVariable ( ref var) => ~[ Constraint { class : Name { name : intern ( "Monad" ) , uid : 0 } , variables : ~[ var. clone ( ) ] } ] ,
627
626
_ => ~[ ]
628
627
} ;
629
628
let typ = function_type_ ( m_a, function_type_ ( m_b. clone ( ) , m_b) ) ;
@@ -641,7 +640,7 @@ impl <'a> Translator<'a> {
641
640
let m_b = result. get_type ( ) . clone ( ) ;
642
641
debug ! ( "m_a {}" , m_a) ;
643
642
let c = match * m_a. appl ( ) {
644
- TypeVariable ( ref var) => ~[ Constraint { class : intern ( "Monad" ) , variables : ~[ var. clone ( ) ] } ] ,
643
+ TypeVariable ( ref var) => ~[ Constraint { class : Name { name : intern ( "Monad" ) , uid : 0 } , variables : ~[ var. clone ( ) ] } ] ,
645
644
_ => ~[ ]
646
645
} ;
647
646
let arg2_type = function_type_ ( a. clone ( ) , m_b. clone ( ) ) ;
0 commit comments