Question: Type systems Below is the abstract syntax of a language involving integers and strings. The comments describe the intended behavior of each operation. data Expr

 Type systems Below is the abstract syntax of a language involvingintegers and strings. The comments describe the intended behavior of each operation.

Type systems Below is the abstract syntax of a language involving integers and strings. The comments describe the intended behavior of each operation. data Expr = Liti Int Lits String | Add Expr Expr Cat Expr Expr Show Expr -- literal integer value literal string value -- add two integers, producing an integer -- concatenate two strings, producing a string -- convert an integer into a string If an operation is applied to an argument of the wrong type, it causes a type error. As usual, if there is a type error anywhere in an expression, the whole expression is considered type incorrect. In the space below, implement a static type system for this language in Haskell. To do this, you must: Write a type definition that represents the possible types of expressions in the language. Implement the typing relation as a function type of that maps expressions to types. Edit View Insert Format Tools Table 12pt Paragraph B I U Av av T, !!! VX data Sval - Si Int Static vs. dynamic scope Consider the following expression written in a strict, call-by-value language with Haskell-like syntax: let x = 2 in let y = 3 in let foo = (\z -> let y = 10 in x + y + z) in let x = y + 2 in let y = x + 3 in let bar = foo 20 in let x = 20 in bar What is the result of evaluating the expression (i.e. the value bar) if the language uses static scoping? 32 50 What is the result of evaluating the expression (i.e. the value bar) if the language uses dynamic scoping? How many declarations of a variable named "y" are there in this expression? 1 How many references to a variable named "y" are there in this expression? 2

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!