Seems to work for me:

$ ghci
GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/ivan/.ghci
Prelude> import Control.Applicative
Prelude Control.Applicative> let zAppend (ZipList xs) (ZipList ys) = ZipList (xs ++ drop (length xs) ys)
Prelude Control.Applicative> take 10 (getZipList (ZipList [1..4] `zAppend` ZipList [5..])) :: [Int]
[1,2,3,4,9,10,11,12,13,14]
Prelude Control.Applicative> take 10 (getZipList (ZipList [1..] `zAppend` ZipList [5..])) :: [Int]
[1,2,3,4,5,6,7,8,9,10]
Prelude Control.Applicative>

(After all, the `length` call will never get evaluated.)

However, I do prefer your solution to avoid traversing the first list twice, so +0.5 from me.

On 5 June 2018 at 13:36, 박신환 <ndospark320@naver.com> wrote:

Current definion of (<|>) for ZipLists:

ZipList xs <|> ZipList ys = ZipList (xs ++ drop (length xs) ys)

doesn't work if the left argument is infinite. It should be:

ZipList [] <|> ys = ys
xs <|> ZipList [] = xs
ZipList (x:xs) <|> ZipList (_:ys) = ZipList (x : (ZipList xs <|> ZipList ys))

_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries




--
Ivan Lazar Miljenovic
Ivan.Miljenovic@gmail.com
http://IvanMiljenovic.wordpress.com