(USING ML)
(Using ML)
Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be [].
Do not use explicit recursion but use one of the fold functions. Do not write any additional functions, dupList should be the only function.
Q:- Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be [].
Do not use explicit recursion but use one of the fold functions. Do not write any additional functions, dupList should be the only function.
Answer:------
fun dupList l = foldr(fn (a, b) => a::a::b) []
l;
Get Answers For Free
Most questions answered within 1 hours.