Sunil Gautam
Sunil Gautam

Reputation: 49

Haskell recursion of tail function

I have this function

func1 :: Double -> [(Double,Double)] -> Maybe [(Double,Double)]
...............
func2 :: Double -> [(Double,Double)] -> [(Double,Double)]
func2 d [] =  []
func2 d list = 
  let dsegs1 = func1 d list
      dsegs2 = func2 d (tail list)
  in  fromJust dsegs1 ++ dsegs2

The simple flow I would like to achieve in func2 is as follows:

let x = func2 3.0 list
let y = func2 3.0 (tail list)
let z = func2 3.0 (tail (tail list))
let a = func2 3.0 (tail (tail (tail list)))

call func2 n times until it returns nothing at the end and concat x,y,z,..., a.

How would I do that?

Upvotes: 0

Views: 237

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198451

It looks like you want map (func2 3.0) (tails list).

Upvotes: 1

Related Questions