Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Haskell (Yes Haskell) Currying/Uncurrying NEED THIS BELOW (Q: A & B) 5 . Let f :: (a -> a -> a) -> a -> a
Haskell (Yes Haskell)
Currying/Uncurrying
NEED THIS BELOW (Q: A & B)
5. Let f :: (a -> a -> a) -> a -> a -> a.
A. Rewrite f * (2 3) so that it has no syntax errors and yields 6 if f h x y = h x y
B. Write the definition of a function g :: ((a, a) -> a, (a, a))-> a so that g is an uncurried version of f. Calling your function on *, 2, and 3 should yield 6.
Here is more Information if needed (Examples)
C. Currying and Uncurrying (LYaH Ch.6, p.1] Functions that take multiple arguments one after another are said to be "curried". The name has nothing to do with spices, it comes from Haskell Curry, the mathematician / logician/CS person for whom the language Haskell is named. Examples: Below, f is curried and g is uncurried but they produce the same final result. > f x y = x - y > g(x,y) = x - y > f 5 3 v v g(5,3) v a => a -> a -> a >:tf f :: Num > :tg g : : Num a => (a, a) -> a In Haskell, we pretty much always use curried functions, which is why we typically write fcn argl arg2 etc. when calling a multi-argument function. The curry and uncurry functions convert a function from one to the other. Here are their types (I've added extra parentheses to emphasize that they take a 2-argument function and return a 2-argument function). curry :: ((a, b)->C) -> (a -> b->C) uncurry :: (a -> b->c) -> ((a, b)->c) Currying the function g above gives you a function that behaves like f; uncurrying f gives you a function that behaves like g.We say f' and g' are partially applied versions of g and f respectively > g' = curry g > g' 53 V VNV V f' = uncurry f f'(5,3) > We don't have to define f' and g' as intermediate names. > curry g 53 > uncurry f (5,3) You may already have guessed, but curry and uncurry are inverses of each other. > uncurry (curry g) (5,3) > (uncurry . curry) g (5,3) -- recall dot is function composition NVNVNVN > curry (uncurry f) 5 3 > (curry.uncurry) f 5 3 -- don't need spaces around the dot C. Currying and Uncurrying (LYaH Ch.6, p.1] Functions that take multiple arguments one after another are said to be "curried". The name has nothing to do with spices, it comes from Haskell Curry, the mathematician / logician/CS person for whom the language Haskell is named. Examples: Below, f is curried and g is uncurried but they produce the same final result. > f x y = x - y > g(x,y) = x - y > f 5 3 v v g(5,3) v a => a -> a -> a >:tf f :: Num > :tg g : : Num a => (a, a) -> a In Haskell, we pretty much always use curried functions, which is why we typically write fcn argl arg2 etc. when calling a multi-argument function. The curry and uncurry functions convert a function from one to the other. Here are their types (I've added extra parentheses to emphasize that they take a 2-argument function and return a 2-argument function). curry :: ((a, b)->C) -> (a -> b->C) uncurry :: (a -> b->c) -> ((a, b)->c) Currying the function g above gives you a function that behaves like f; uncurrying f gives you a function that behaves like g.We say f' and g' are partially applied versions of g and f respectively > g' = curry g > g' 53 V VNV V f' = uncurry f f'(5,3) > We don't have to define f' and g' as intermediate names. > curry g 53 > uncurry f (5,3) You may already have guessed, but curry and uncurry are inverses of each other. > uncurry (curry g) (5,3) > (uncurry . curry) g (5,3) -- recall dot is function composition NVNVNVN > curry (uncurry f) 5 3 > (curry.uncurry) f 5 3 -- don't need spaces around the dot
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