Question: LIST CONCATENATION - - [ 1 , 2 , 3 ] + + [ 2 , 3 , 4 ] = [ 1 , 2

LIST CONCATENATION
--[1,2,3]++[2,3,4]=[1,2,3,2,3,4]
--[1,2,3]++[1]=[1,2,3,4]
--
--LIST PREPENDING
--1 : [2,3]=[1,2,3]
--
--LIST APPENDING
--[2,3] : 2= WRONG
--[2,3]++[2]=[2,3,2]
--2 : 3 : 4 : []=[2,3,4]
--
--LIST FUNCTIONS
--head [1,2,3,4]=1
--tail [1,2,3,4]=[2,3,4]
--length [1,2,3,4]=4
--[1,2,3,4]!!0=1
--[1,2,3,4]!!3=4
--filter (\x -> x >2)[1,2,3,4,5]=[3,4,5]
--reverse [2,3,4]=[4,3,2]
--map reverse ["abc", "def", "ghi"]=["cba", "fed", "ihg"]
--
--LIST COMPREHENSIONS
--[1..3]=[1,2,3]
--[1,3..13]=[1,3,5,7,9,11,13]
--[even x | x <-[1..10]]=[2,4,6,8,10]
--
--
--Use the above functions to achieve the specified goals.
--For each function write its type signature if not present.
-- Problem 2A. Write a function that takes a list and puts the last two elements
-- at the front of the list, in their original order. For lists of size
-- one, return the original list. For empty lists, return the empty list.
--
--ex:
--INPUT: func_2a [1,2,3,4,5]
--OUTPUT: [4,5,1,2,3]
--INPUT: func_2a "ceni"
--OUTPUT: "nice"
--INPUT: func_2a []
--OUTPUT: []
--
-- PUT THE LAST TWO LIST ELEMENTS AT THE FRONT OF THE LIST
--4 pts
func_2a :: [a]->[a]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!