Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago