Skip to content

Instantly share code, notes, and snippets.

@treeowl
Created May 14, 2019 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treeowl/3e149df5a03c3ae2e51c51277919e189 to your computer and use it in GitHub Desktop.
Save treeowl/3e149df5a03c3ae2e51c51277919e189 to your computer and use it in GitHub Desktop.
zipRev :: [a] -> [b] -> [(a,b)]
zipRev xs ys = fr where
(fr, allbs) = go [] allbs xs ys
go acc ~(b':bs') (a:as) (b:bs) = ((a,b') : res, bss)
where
(res, bss) = go (b:acc) bs' as bs
go acc _ _ _ = ([], acc)
@treeowl
Copy link
Author

treeowl commented May 14, 2019 via email

@WillNess
Copy link

WillNess commented May 14, 2019

It just aligns the lists at the wrong end:

   1   2   3   4
       12  11  10  -- OP's code
   12  11  10      -- your code

About that, could you remind me, with the link to the SO entry? I remembered something vaguely about this, recently, but couldn't remember exactly what it was...

@treeowl
Copy link
Author

treeowl commented May 14, 2019

I don't know about the SO comment, but here's the GitHub issue. Remember: the function must be incremental/lazy the way liftA2 is, and must be time and space-optimal. You will almost certainly need to mash up ideas from the internal functions aptyMiddle (which I created to implement (<*>) and later liftA2) and applicativeTree (which was created, I believe by Wasserman, to implement replicateA and thereby replicate) to accomplish this mission.

@WillNess
Copy link

thanks, will try to see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment