简体   繁体   中英

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?

看起来您想要map (func2 3.0) (tails list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM