0
trace :: String -> Float -> Colour -> [ColouredLine]  
trace (c:cs) angle colour  
 = trace' (c:cs) angle colour (0.0,0.0)  
  where  
   trace' "" angle colour intvertex = []  
   trace' (c:cs) angle colour intvertex  
       | c == 'R' = trace' cs (angle-90) colour intvertex  
       | c == 'L' = trace' cs (angle+90) colour intvertex  
       | c == 'F' = [(intvertex,aftvertex,colour)] ++ trace' cs angle colour aftvertex  
         where  
           aftvertex = fst (move 'F' (intvertex,angle) angle) 

报告:

跟踪“F[RF][LF][FF]”45.0 (1.0,0.0,0.0) = 例外:LSystems.hs:(95,4)-(101,61):函数跟踪中的非详尽模式'

预期测试用例:

[((-8.742278e-8,2.0),(-1.3113416e-7,3.0),(1.0,0.0,0.0)),((-4.371139e-8,1.0),(-0.7071068,1.7071068),( 1.0,0.0,0.0)),((-4.371139e-8,1.0),(-8.742278e-8,2.0),(1.0,0.0,0.0)),((-4.371139e-8,1.0),( 0.7071067,1.7071068),(1.0,0.0,0.0)),((0.0,0.0),(-4.371139e-8,1.0),(1.0,0.0,0.0))]

4

1 回答 1

4

您的测试字符串包含“[”和“]”,但您在模式匹配中只匹配“R”、“L”和“F”。因此,一旦它到达方括​​号,就会出现异常。

于 2015-01-01T20:26:12.457 回答