WestCoastProjects
WestCoastProjects

Reputation: 63022

"The compiler is unable to type-check this expression in reasonable time" for a simple formula

I have what appears to be a rather simple arithmetic expression:

       let N = 2048
//        var c = (0..<N).map{ sin( 2.0 * .pi * Float($0) / (Float(N)/2.0)) }
        let sinout = (0..<N * 10).map { x in
            sin(2 * .pi * Float(x) / Float(N / 2))
        }

But this is generating:

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

enter image description here

Why is such a simple equation not parse-able by the Swift compiler? How do we write equations that Swift can actually parse? This must be a major headache for persons writing DSP and/or linear algebra libraries: what workarounds or patterns do you use?

Upvotes: 0

Views: 106

Answers (2)

Leo Dabus
Leo Dabus

Reputation: 236260

You just have to explicitly set the return type of your map expression:

map { x -> Float in

Upvotes: 2

ERP
ERP

Reputation: 333

Sometimes it is hard for Swift to compile some seemingly easy code. The best thing you can do in those cases is modulate it in smaller chunks. I honestly think that this is an error that should be fixed but that for some reason is still there.

Upvotes: 1

Related Questions