About
In the first line, we define the type signature for initsegs which takes a list of any type a and returns a list of lists of type [a].
In the second line, we define the base case of the recursion, which is when the input list is empty. In this case, we simply return a list containing the empty list.
In the third line, we define the recursive case of the function. Here, we pattern match on the input list to extract the head x and the tail xs. We then recursively call initsegs on the tail xs to obtain a list of all initial segments of xs. We use map to prepend x to each of these initial segments, and finally we prepend the empty list [] to the beginning of the resulting list to obtain the full list of initial segments.
Here's an example of using the initsegs function code initsegs :: [a] -> [[a]]
initsegs [] = [[]]
initsegs (x:xs) = [[]] ++ map (x:) (initsegs xs)
example initsegs [1,2,3] [[],[1],[1,2],[1,2,3]]