Question

Question in Haskell language? Suppose that oho is the list ['o', 'h', 'n', 'o'] and that...

Question in Haskell language?

Suppose that oho is the list ['o', 'h', 'n', 'o'] and that yikes is the list "yikes". For each of the following, say whether it is legal or illegal in Haskell. And wy is it illegal?

1. ohno:'y'

2. ohno ++ yikes

3. ohno:yikes

4. ['o']:yikes

5. 'o':yikes

Homework Answers

Answer #1

1. ohno:'y'

: is the “prepend” operator. So [] is list and x:[] is prepending x to list.

this statement is illegal as the variable on left side of (:) is a list rather than an element.

2. ohno ++ yikes

this is concatenation of list. As both are list this statement is lega.

3. ohno:yikes

This is illegal. Reason is same as 1. We are prepending list to a list but (:) operator prepend only single element.

4. ['o']:yikes

this is illegal. ['o'] is a list of single character.

5. 'o':yikes

this is legal statement. as we are prepending 'o' a single char appending to list of char. yikes is list of char

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
Haskell Complete the following function definition: stutter n x should return a list of length n...
Haskell Complete the following function definition: stutter n x should return a list of length n where each element is x. E.g., stutter 3 5 = [5,5,5]. Use a list comprehension to produce the result. Note stutter 0 x = []. Don't worry about n < 0; the canonical solution makes stutter return []. stutter n x = ???
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Which of the following elements can have an expanded octet? 1-O 2-Cl 3- N 4-H 5-...
Which of the following elements can have an expanded octet? 1-O 2-Cl 3- N 4-H 5- He
i) F o r t h e f o l l o w I n g...
i) F o r t h e f o l l o w I n g f i n d t h e ( c o m p. E x p.) f o u r I e r s e r i e s f o r x( t ) I I ) D r a w t h e am p &. P h a s e s p e c t r a I I I ) T...
(a) Construct a 2 - 3 tree for the list f,l,o,w,c,h,a,r,t,i,n,g. Use the alphabetical order of...
(a) Construct a 2 - 3 tree for the list f,l,o,w,c,h,a,r,t,i,n,g. Use the alphabetical order of the letters to compare them and insert them successively starting with the empty tree. (b) Assuming that the probabilities of searching for each of the keys (i.e., the letters) are the same, find the largest number and the average number of key comparisons for successful searches in this tree.
Question 1 A 100 g sample with 40.92% C, 4.58% H, and 54.50% O by mass...
Question 1 A 100 g sample with 40.92% C, 4.58% H, and 54.50% O by mass contains A.      40.92 moles C B.      1 mole C C.       3.407 moles C D.      0.2935 moles C Part B The ratio of the number of moles of C,H, and O in the last problem is A.      1:2:3 B.      3.407:4.54:3.406 C.       3.407:1:2 D.      3:4:3 Part C The simplest whole number ratio of C to H to O in problem #1 is: A.      3:4:5 B.      1:1:1...
(a) Construct a 2−3 tree for the list f,l,o,w,c,h,a,r,t,i,n,g. Use the alphabetical order of the letters...
(a) Construct a 2−3 tree for the list f,l,o,w,c,h,a,r,t,i,n,g. Use the alphabetical order of the letters to compare them and insert them successively starting with the empty tree. (b) Assuming that the probabilities of searching for each of the keys (i.e., the letters) are the same, find the largest number and the average number of key comparisons for successful searches in this tree. Full description plz
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Suppose your code contains a loop that runs once for each number in a list. Assume...
Suppose your code contains a loop that runs once for each number in a list. Assume there are 4 basic steps of work to do before the loop and 2 after, and the loop does 3 meaningful steps of work for each iteration of the loop. You may assume that a basic step of work is represented as 1. (a) Write an expression to describe the work of the program in terms of the size of the list. Refer to...
JAVA - algorithm analysis and sorting Question 1 Which of the following features grows fastest? 1....
JAVA - algorithm analysis and sorting Question 1 Which of the following features grows fastest? 1. N2 2. log N 3. N log N 4. N 5. 10 Question 2 Given the following code segment: for( int i = 1; i < n; i++ ) for( int j = 1; j < i; j++ ) k = k + i + j; What is the runtime of the code segment? 1. None of the above 2. O(i*N) 3. O(N2) 4....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT