fn infer(&mut self, infer: &mut InferState<'_>) -> Result<()> {
        let constraints = self.init.infer(infer)?;

        infer.solve(&constraints);

        // Apply substitution to the type environment
        infer.env.apply_mut(infer.sub);

        let t = self.init.type_of().apply(infer.sub);
        let p = infer::generalize(&infer.env, infer.sub.cons(), t);

        // Update variable assignment nodes with the free vars
        // and kind constraints obtained from generalization.
        //
        // Note these variables are fixed after generalization
        // and so it is safe to update these nodes in place.
        self.vars = p.vars.clone();
        self.cons = p.cons.clone();

        // Update the type environment
        infer.env.add(self.id.name.clone(), p);
        Ok(())
    }
// Polymorphic generalization, necessary for let-polymorphism, is
// implemented here.
//
// In particular, for every variable assignment we infer the type of
// its corresponding expression. We then generalize that type by
// quantifying over all of its free type variables. Finally we bind
// the variable to its newly generalized type in the type environment
// before inferring the rest of the program.
//
Polymorphic generalization, necessary for let-polymorphism, is
implemented here.

In particular, for every variable assignment we infer the type of
its corresponding expression. We then generalize that type by
quantifying over all of its free type variables. Finally we bind
the variable to its newly generalized type in the type environment
before inferring the rest of the program.
Polymorphic generalization necessary for let - polymorphism is implemented here . In particular for every variable assignment we infer the type of its corresponding expression . We then generalize that type by quantifying over all of its free type variables . Finally we bind the variable to its newly generalized type in the type environment before inferring the rest of the program .
fn infer(&mut self, infer: &mut InferState<'_>) -> Result<()> {
        let constraints = self.init.infer(infer)?;
        infer.solve(&constraints);
        // Apply substitution to the type environment
        infer.env.apply_mut(infer.sub);
        let t = self.init.type_of().apply(infer.sub);
        let p = infer::generalize(&infer.env, infer.sub.cons(), t);
        // Update variable assignment nodes with the free vars
        // and kind constraints obtained from generalization.
        //
        // Note these variables are fixed after generalization
        // and so it is safe to update these nodes in place.
        self.vars = p.vars.clone();
        self.cons = p.cons.clone();
        // Update the type environment
        infer.env.add(self.id.name.clone(), p);
        Ok(())
    }
fn infer ( & mut self , infer : & mut InferState < ' _ > ) -> Result < ( ) > { let constraints = self . init . infer ( infer ) ? ; infer . solve ( & constraints ) ; // Apply substitution to the type environment infer . env . apply_mut ( infer . sub ) ; let t = self . init . type_of ( ) . apply ( infer . sub ) ; let p = infer :: generalize ( & infer . env , infer . sub . cons ( ) , t ) ; // Update variable assignment nodes with the free vars // and kind constraints obtained from generalization. // // Note these variables are fixed after generalization // and so it is safe to update these nodes in place. self . vars = p . vars . clone ( ) ; self . cons = p . cons . clone ( ) ; // Update the type environment infer . env . add ( self . id . name . clone ( ) , p ) ; Ok ( ( ) ) }
Polymorphic generalization, necessary for let-polymorphism, is
implemented here.
Polymorphic generalization necessary for let - polymorphism is implemented here .
&mut self
infer
&mut InferState<'_>
&mut self
infer
&mut InferState<'_>