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
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
Get Answers For Free
Most questions answered within 1 hours.