代写 1 Example

1 Example
addThree :: Int− > Int− > Int− > Int addT hree x y z = x + y + z
The Types of:
• • •
addThree2
Answer: Int− > Int− > Int− > Int
addThree23
Answer: Int− > Int− > Int− > Int
addThree234
Answer: Int− > Int− > Int− > Int
Exercises
Exercise 1 – Types
Hao Tian March 2019
2
f :: a− > String
f x = ”Hello”
g ::[a]−>Int−>[a]
g x n = concat (replicate n x)
Given above, please write down types of the following expressions (they may include type error):
1. f “abc” Answer: String
2. g “abc” Answer: Int − > [Char]
3. replicate 3 Answer: a − > [a]
4. concat[′a′,′ b′,′ c′] Answer: Type Error
5. concat[“a”, “b”, “c”] Answer: [Char]
6. g (f “abc”) Answer: Int − > [Char]
7. g (f “abc”) 3 Answer: [Char]
8. h1 = f . g
type of: h1 “abc” Answer: String
9. h2 = (f .) . g
type of: h2 “abc” Answer: Int − > String
1