Question: In Haskell 2.2 Assignment Part II: Monomorphic type inference In this part, we will write a simple type inference algorithm that handles only monomorphic types,

In Haskell In Haskell 2.2 Assignment Part II: Monomorphic type inference In this part,

2.2 Assignment Part II: Monomorphic type inference In this part, we will write a simple type inference algorithm that handles only monomorphic types, i.e. those excluding type variables and user-defined functions. Define a function monomorphicInferType :: Expr TEnv Type that, given an expression and a type environment, will infer the type of the given expression using the rules outlined in section 1.5 above. For the case of identifiers, e.g. Id i, you may assume that there will be a binding for i in the given type environment. For such bindings, you may assume that the type does not include type variables (via constructor TVar). Please note that the given expression is guaranteed not to contain any user-defined functions, so your code should not handle the Fun constructor. It does need to handle the Number, Boolean, Id, Prim, Cond, and App constructors. If there is a type error in the given expression, monomorphicInferType should return TErr. Below are some examples of the use of monomorphicInferType, assuming that env is defined as follows: env :: TEnv env =[("x", TInt ),("y", TInt ),("b", TBool ),("c", TBool )] 2.2 Assignment Part II: Monomorphic type inference In this part, we will write a simple type inference algorithm that handles only monomorphic types, i.e. those excluding type variables and user-defined functions. Define a function monomorphicInferType :: Expr TEnv Type that, given an expression and a type environment, will infer the type of the given expression using the rules outlined in section 1.5 above. For the case of identifiers, e.g. Id i, you may assume that there will be a binding for i in the given type environment. For such bindings, you may assume that the type does not include type variables (via constructor TVar). Please note that the given expression is guaranteed not to contain any user-defined functions, so your code should not handle the Fun constructor. It does need to handle the Number, Boolean, Id, Prim, Cond, and App constructors. If there is a type error in the given expression, monomorphicInferType should return TErr. Below are some examples of the use of monomorphicInferType, assuming that env is defined as follows: env :: TEnv env =[("x", TInt ),("y", TInt ),("b", TBool ),("c", TBool )]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!