Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started