Merging two lists in Haskell

前端 未结 6 1561
轮回少年
轮回少年 2020-11-29 09:26

Can\'t figure out how to merge two lists in the following way in Haskell:

INPUT:  [1,2,3,4,5] [11,12,13,14]

OUTPUT: [1,11,2,12,3,13,4,14,5]         


        
6条回答
  •  伪装坚强ぢ
    2020-11-29 09:38

    I want to propose a lazier version of merge:

    merge [] ys = ys
    merge (x:xs) ys = x:merge ys xs
    

    For one example use case you can check a recent SO question about lazy generation of combinations.
    The version in the accepted answer is unnecessarily strict in the second argument and that's what is improved here.

提交回复
热议问题