[Solved] Haskell join function inputs in list in specific order


Well since you got it working without the starting/ending point. An easy way to complete would be use your function but add the starting/ending point in the list in an inner function. So your interface is still same.

Another way using recursion, pattern matching and guards is:

-- assuming the inputs to be int as definition of point not given
solve x z [] = [(x,z)]

solve x z (y:ys)
            | x == 0 = solve y z ys     -- x ==0 to be replaced by null/empty condition on x
            | null ys && z == 0 = []    -- z ==0 to be replaced by null/empty condition on z
            | null ys = [(y, z)]
            | otherwise = (x,y) : solve y z ys

Added a base case when the list is empty or start/end points not valid based on darthfennec comment.

2

solved Haskell join function inputs in list in specific order