Search code examples
haskellnon-exhaustive-patterns

Non-exhaustive patterns in function trace'


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) 

REPORT:

trace "F[RF][LF][FF]" 45.0 (1.0,0.0,0.0) = Exception: LSystems.hs:(95,4)-(101,61): Non-exhaustive patterns in function trace'

Test case expected:

[((-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))]


Solution

  • Your test string contains '[' and ']', but you only match 'R', 'L' and 'F' in your pattern match. So as soon as it reaches a square bracket you get an exception.