Haskell Without looking at the definitions from the standard prelude, define the following library functions on lists using recursion. a. Decide if all logical values in a list are "True": and :: [Bool] -> Bool b. Concatenate a list of lists: concat :: [la]] -> [a] Note: most of these functions are defined in the prelude using other library functions rather than using explicit recursion, and are generic functions rather than being specific to the type of lists.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).

1: Define the exponentiation operator ↑ for non-negative integers
-- using the same pattern of recursion as the multiplication operator ∗,
-- and show how 2 ↑ 3 is evaluated using your definition.
power base 0 = 1
power base exponent = base * power base (exponent-1)
-- 3: Without looking at the definitions from the standard prelude in Appendix B,
-- define the following library functions using recursion:
-- • Decide if all logical values in a list are True:
myAnd :: [Bool] -> Bool
myAnd [] = True
myAnd (False:rest) = False
myAnd (True:rest) = myAnd rest
-- • Concatenate a list of lists:
myConcat :: [[a]] -> [a]
myConcat [] = []
myConcat (list:lists) = list ++ concat lists
-- • Produce a list with n identical elements:
myReplicate :: Int -> a -> [a]
myReplicate 0 obj = []
myReplicate size obj = obj : myReplicate (size-1) obj
-- • Select the nth element of a list:
myAt :: [a] -> Int -> a
myAt (element:elements) 0 = element
myAt (element:elements) n = myAt elements (n-1)
Step by step
Solved in 2 steps









