Question

Haskell Let f x y z = x : ( [ y ] : [ z...

Haskell

Let f x y z = x : ( [ y ] : [ z ] ). What is the type of f?

Homework Answers

Answer #1

The syntax provided in the question represents a Haskell function 'f' which takes three arguments 'x','y' and 'z' as input to the function at the time of function call.

By seeing the definition of function 'f', we deduce that the variable 'z' is of 'list' type since it is enclosed within square brackets ( [ ] ). Now, the type of ' [ y ] ' must be 'list' since it has to be combined with the list 'z' to form a resultant list ( Here, the operator ' : ' combines the two lists on either side to form a resultant list containing the two lists ). Therefore, to make the type of '[ y ]' to be list, the type of variable 'y' must be any basic type such as Char, Num, Fractional, etc since the square brackets will automatically convert it into a list. Accordingly, the variable 'x' must be of 'list' type since it has to be combined with the other two lists 'y' and 'z' by the ' : ' operator. The resultant would be a list containing the three lists.

Now, the operation of function 'f' is to return a list that contains the list x, list y and list z serially. This implies that the function 'f' is combining the three lists. Hence, one should keep in mind that the elements of list 'x' and list 'z' should be of the same type as the type of the variable 'y', otherwise, the lists would not be combined and the compiler would throw an error.

Hence, the return type of function 'f' is list of lists ( that is, a list containing other lists ) and the elements of the inner lists are of the type of the variable 'y' ( which can be any basic type , that is Char, Num, Fractional, etc. ).

GHCi, version 8.6.5 > let fx y z = x : ([y] : [ z ]) ?:tf f:: [a] -> a -> [a] -> [[a]] If [1,2] 5 [7,9] => [[1,2],[5],[7,9]] f['c', 'h'] 'e' ['g','g'] => ["ch", "e", "gg"]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Let X, Y and Z be sets. Let f : X → Y and g :...
Let X, Y and Z be sets. Let f : X → Y and g : Y → Z functions. (a) (3 Pts.) Show that if g ◦ f is an injective function, then f is an injective function. (b) (2 Pts.) Find examples of sets X, Y and Z and functions f : X → Y and g : Y → Z such that g ◦ f is injective but g is not injective. (c) (3 Pts.) Show that...
Let F ( x , y , z ) =< e^z sin( y ) + 3x...
Let F ( x , y , z ) =< e^z sin( y ) + 3x , e^x cos( z ) + 4y , cos( x y ) + 5z >, and let S1 be the sphere x^2 + y^2 + z^2 = 4 oriented outwards Find the flux integral ∬ S1 (F) * dS. You may with to use the Divergence Theorem.
8.4: Let f : X → Y and g : Y→ Z be maps. Prove that...
8.4: Let f : X → Y and g : Y→ Z be maps. Prove that if composition g o f is surjective then g is surjective. 8.5: Let f : X → Y and g : Y→ Z be bijections. Prove that if composition g o f is bijective then f is bijective. 8.6: Let f : X → Y and g : Y→ Z be maps. Prove that if composition g o f is bijective then f is...
1.) Let f ( x , y , z ) = x ^3 + y +...
1.) Let f ( x , y , z ) = x ^3 + y + z + sin ⁡ ( x + z ) + e^( x − y). Determine the line integral of f ( x , y , z ) with respect to arc length over the line segment from (1, 0, 1) to (2, -1, 0) 2.) Letf ( x , y , z ) = x ^3 * y ^2 + y ^3 * z^...
Show the following: a) Let there be Y with the cumulative distribution function F(y). Let F(Y)=Z....
Show the following: a) Let there be Y with the cumulative distribution function F(y). Let F(Y)=Z. Show that Z~U(0,1) for F(y). b) Let X~U(0,1), and let Y := -ln(X). Show that Y~exp(1)
(a) Let f(z) = z^2. R is bounded by y = x, y= -x and x...
(a) Let f(z) = z^2. R is bounded by y = x, y= -x and x = 1. Find the image of R under the mapping f. (b)Find the all values of (-i)^(i) (c)Find the all values of (1-i)^(4i)
Let X = { x, y, z }. Let the list of open sets of X...
Let X = { x, y, z }. Let the list of open sets of X be Z1. Z1 = { {}, {x}, X }. Let Y = { a, b, c }. Let the list of open sets of Y be Z2. Z2 = { {}, {a, b}, Y }. Let f : X --> Y be defined as follows: f (x) = a, f (y) = b, f(z) = c Is f continuous? Prove or disprove using the...
Let F~ (x, y, z) = x cos(x 2 + y 2 − z 2 )~i...
Let F~ (x, y, z) = x cos(x 2 + y 2 − z 2 )~i + y cos(x 2 + y 2 − z 2 )~j − z cos(x 2 + y 2 − z 2 ) ~k be the force acting on a particle at location (x, y, z). Under this force field, the particle is moved from the point P = (1, 1, 1) to Q = (0, 0, √ π). What is the work done by...
Problem 10. Let F = <y, z − x, 0> and let S be the surface...
Problem 10. Let F = <y, z − x, 0> and let S be the surface z = 4 − x^2 − y^2 for z ≥ 0, oriented by outward-pointing normal vectors. a. Calculate curl(F). b. Calculate Z Z S curl(F) · dS directly, i.e., evaluate it as a surface integral. c. Calculate Z Z S curl(F) · dS using Stokes’ Theorem, i.e., evaluate instead the line integral I ∂S F · ds.
Let f(x,y,z)=yz/x. Use linearization (or differentials) to approximate f(1.01,2.04,2.97)
Let f(x,y,z)=yz/x. Use linearization (or differentials) to approximate f(1.01,2.04,2.97)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT