Question: Part 2: Type inference Below are several type definitions. You do not need to know the implementations of the functions or the undefined Glob' type

 Part 2: Type inference Below are several type definitions. You donot need to know the implementations of the functions or the undefined

Part 2: Type inference Below are several type definitions. You do not need to know the implementations of the functions or the undefined Glob' type in order to solve the problems. data Result a = OK a Error String show :: Glob -> String build :: Int -> Glob (.) :: (b-> c) -> (a -> b)-> a -> C Part 2.1: Determine the type of a sub-expression For each of the following problems, determine what the type of the unknown value must be in order for the overall expression to have the given type. For example, given the following facts: build foo :: Glob bar True :: Int -> Int Then it must be the case that 'foo' and 'bar' have the following types: foo :: Int bar :: Bool -> Int -> Int (Brief explanation: 'foo' must be an 'Int' since it's passed as an argument to 'build', and 'bar' is a function that returns a function from 'Int -> Int' when given one 'Bool'.) 1. Given the following fact, what is the type of 'foo'? OK (show foo) :: Result String foo :: 2. Given the following fact what is the type of 'bazi? 2. Given the following fact, what is the type of 'baz'? show . bar :: String -> String bar :: Part 2.2: Construct a value of the given type For each of the following problems, create an expression of the indicated type using only the types and functions defined above. 1. Result (Int -> Glob) 2. Glob -> Result a Part 2: Type inference Below are several type definitions. You do not need to know the implementations of the functions or the undefined Glob' type in order to solve the problems. data Result a = OK a Error String show :: Glob -> String build :: Int -> Glob (.) :: (b-> c) -> (a -> b)-> a -> C Part 2.1: Determine the type of a sub-expression For each of the following problems, determine what the type of the unknown value must be in order for the overall expression to have the given type. For example, given the following facts: build foo :: Glob bar True :: Int -> Int Then it must be the case that 'foo' and 'bar' have the following types: foo :: Int bar :: Bool -> Int -> Int (Brief explanation: 'foo' must be an 'Int' since it's passed as an argument to 'build', and 'bar' is a function that returns a function from 'Int -> Int' when given one 'Bool'.) 1. Given the following fact, what is the type of 'foo'? OK (show foo) :: Result String foo :: 2. Given the following fact what is the type of 'bazi? 2. Given the following fact, what is the type of 'baz'? show . bar :: String -> String bar :: Part 2.2: Construct a value of the given type For each of the following problems, create an expression of the indicated type using only the types and functions defined above. 1. Result (Int -> Glob) 2. Glob -> Result a

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!