一个简单的公式,“编译器无法在合理的时间中对该表达式进行类型检查”

时间:2020-06-16 01:43:54

标签: swift compiler-errors

我有一个似乎很简单的算术表达式:

       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))
        }

但这正在生成:

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

为什么Swift编译器无法解析这样一个简单的方程式?我们如何编写Swift可以实际解析的方程式?对于编写DSP和/或线性代数库的人们来说,这一定是一个头疼的问题:您使用什么变通方法或模式?

2 个答案:

答案 0 :(得分:2)

您只需显式设置地图表达式的返回类型:

id  col_a col_b record_times
1    d     d        1
2    d     1        1
3    3     4        1
4    d     d        2
5    d     1        2
6    3     4        2
7    d     d        3
8    d     1        3
9    3     4        3

答案 1 :(得分:1)

有时候,Sw​​ift很难编译一些看似简单的代码。在这些情况下,您可以做的最好的事情是将其调制成较小的块。老实说,我认为这是应该修复的错误,但由于某些原因仍然存在。