Hello everyone, I'm new here and have browsed through some discussions and found it useful. I was wondering if anyone could help me with a functional programming problem in Haskell.
Im trying to define a function seg, which is supposed to take a finite list xs as its argument and returns the list of all the segments xs. What is meant by a segment, is a list of adjacent elements i.e.
seg [1,2,3] = [[1,2,3], [1,2], [2,3], [1], [2], [3]]
Ive given it a shot, but my program is partially working with wrong output, i get
seg [1,2,3] = [[1,2,3],[1,3],[2,3],[3]]
Here is my code,...
cons :: Int -> [Int] -> [Int]
cons x l = (x:l)
seg :: [Int] -> [[Int]]
seg [] = []
seg [x] = [[x]]
seg (x:xs) = (map (cons x) (seg xs)) ++ seg xs
I'll be grateful if anyone can help me, because it is one of the last few questions that i have to do before next week. Will be mega :lol: when its over.
Can you please email optimak@gmail.com to let me know, or do i just regularly check the forums.
Thanks very much