pgujjula / apply-merge

Lift a binary, non-decreasing function onto ordered lists and order the output
8 stars 1 forks source link

Add laziness test #13

Open pgujjula opened 1 month ago

pgujjula commented 1 month ago

For ApplyMerge.DoublyLinkedList.applyMerge, the following is not productive

primes :: [Int]
primes = 2 : ([3 ..] `minus` composites)

composites :: [Int]
composites = applyMerge (*) primes [2 ..]

And we instead need to write primes = 2 : 3 : ([5 ..] `minus` composites).

Add a test checking that applyMerge implementations are productive given the above example, and fix ApplyMerge.DoublyLinkedList.applyMerge to pass the test.

pgujjula commented 1 month ago

If applyMerge = flip . ApplyMerge.DoublyLinkedList.applyMerge . flip, then we need to write primes = 2 : 3 : 5 : ([7 ..] `minus` composites) to get a productive output.