@@ -140,9 +140,10 @@ impl Type {
140140 }
141141 }
142142
143- // pub fn contains(&self,)
144-
145- /// Simplify an expression until it matches a given function.
143+ /// Simplify an expression until it matches a given function which "approves" of a type.
144+ /// This will perform template applications to simplify the type if possible as well.
145+ ///
146+ /// This is the **prefered** way to simplify a type into a concrete type.
146147 pub fn simplify_until_matches (
147148 self ,
148149 env : & Env ,
@@ -156,11 +157,7 @@ impl Type {
156157 if f ( & simplified, env) ? || simplified. is_atomic ( ) {
157158 return Ok ( simplified) ;
158159 }
159- simplified = simplified. simplify ( env) ?. perform_template_applications (
160- env,
161- & mut HashMap :: new ( ) ,
162- 0 ,
163- ) ?
160+ simplified = simplified. simplify ( env) ?. perform_template_applications ( env, & mut HashMap :: new ( ) ) ?
164161 }
165162 Err ( Error :: CouldntSimplify ( simplified, expected) )
166163 }
@@ -476,7 +473,6 @@ impl Type {
476473 & self ,
477474 env : & Env ,
478475 previous_applications : & mut HashMap < ( Type , Vec < Type > ) , Type > ,
479- i : usize ,
480476 ) -> Result < Self , Error > {
481477 // If the type is an Apply on a Poly, then we can perform the application.
482478 // First, perform the applications on the type arguments.
@@ -497,25 +493,19 @@ impl Type {
497493
498494 match poly {
499495 Self :: Poly ( params, template) => {
500- let save = template. clone ( ) ;
501496 let mut template = * template;
502497 for ( param, ty_arg) in params. iter ( ) . zip ( ty_args. iter ( ) ) {
503498 template = template. substitute ( param, ty_arg) ;
504499 }
505- // template = template.simplify(env)?;
506- // previous_applications.insert((Self::Poly(params, save), ty_args), template.clone());
507500 Ok ( template)
508501 }
509502 Self :: Symbol ( s) => {
510503 match env. get_type ( s. as_str ( ) ) . cloned ( ) {
511504 Some ( Self :: Poly ( params, template) ) => {
512- let save = template. clone ( ) ;
513505 let mut template = * template;
514506 for ( param, ty_arg) in params. iter ( ) . zip ( ty_args. iter ( ) ) {
515507 template = template. substitute ( param, ty_arg) ;
516508 }
517- // template = template.simplify(env)?;
518- // previous_applications.insert((Self::Poly(params, save), ty_args), template.clone());
519509 Ok ( template)
520510 }
521511 Some ( other) => Ok ( Self :: Apply ( Box :: new ( other) , ty_args) ) ,
@@ -771,14 +761,12 @@ impl Type {
771761 }
772762
773763 ( Self :: Apply ( poly, ty_args) , b) | ( b, Self :: Apply ( poly, ty_args) ) => {
774- let a = Self :: Apply ( poly. clone ( ) , ty_args. clone ( ) ) ;
775764 // If the type is a polymorphic type, then we need to simplify it first.
776765 let f = poly. clone ( ) . simplify_until_matches (
777766 env,
778767 Type :: Poly ( vec ! [ ] , Box :: new ( Type :: Any ) ) ,
779- |t, env | Ok ( matches ! ( t, Type :: Poly ( _, _) ) ) ,
768+ |t, _env | Ok ( matches ! ( t, Type :: Poly ( _, _) ) ) ,
780769 ) ?;
781- // let a = a.simplify_until_matches(env, Type::Any, |t, env| Ok(t.is_simple()))?;
782770
783771 match f {
784772 Self :: Poly ( ty_params, mut template) => {
@@ -789,12 +777,6 @@ impl Type {
789777 }
790778 template. equals_checked ( b, compared_symbols, env, i) ?
791779 }
792- // // Self::Symbol(_) => {
793- // // // If the type is not a polymorphic type, then we can compare it to the
794- // // // other type.
795- // // // return a.equals_checked(b, compared_symbols, env, i);
796- // // false
797- // // }
798780 _ => {
799781 // If the type is not a polymorphic type, then we can compare it to the
800782 // other type.
@@ -873,7 +855,7 @@ impl Type {
873855 Type :: Apply ( _, _) | Type :: Poly ( _, _) => {
874856 let t = self
875857 . clone ( )
876- . simplify_until_matches ( env, Type :: Any , |t, env | {
858+ . simplify_until_matches ( env, Type :: Any , |t, _env | {
877859 Ok ( !matches ! (
878860 t,
879861 Type :: Let ( _, _, _)
@@ -958,7 +940,7 @@ impl Type {
958940 Type :: Apply ( _, _) | Type :: Poly ( _, _) => {
959941 let t = self
960942 . clone ( )
961- . simplify_until_matches ( env, Type :: Any , |t, env | {
943+ . simplify_until_matches ( env, Type :: Any , |t, _env | {
962944 Ok ( !matches ! (
963945 t,
964946 Type :: Let ( _, _, _)
@@ -1179,7 +1161,7 @@ impl fmt::Display for Type {
11791161 }
11801162
11811163 Self :: Symbol ( name) => write ! ( f, "{name}" ) ,
1182- Self :: Unit ( unit_name, ty ) => write ! ( f, "unit {unit_name}" ) ,
1164+ Self :: Unit ( unit_name, _ty ) => write ! ( f, "unit {unit_name}" ) ,
11831165 Self :: Let ( name, ty, ret) => write ! ( f, "let {name} = {ty} in {ret}" ) ,
11841166 }
11851167 }
0 commit comments