Haskell style/efficiency

后端 未结 2 2091
太阳男子
太阳男子 2021-01-12 22:11

So I was working on a way to lazily generate primes, and I came up with these three definitions, which all work in an equivalent way - just checking whether each new intege

2条回答
  •  死守一世寂寞
    2021-01-12 22:15

    Note that primes3 can be made more efficient by changing ps++[x] to (x:ps). The running (++) is linear in the length of its left argument, but constant in the length of the right argument.

提交回复
热议问题