我想知道是否有人可以帮助我确定 Haskell 代码中不详尽的部分?我看不出如何在列表末尾不满足基本情况。
多谢
强尼
type Rule
= (Char, String)
type Rules
= [Rule]
type System
= (Float, String, Rules)
cross, triangle, arrowHead, peanoGosper,
dragon, snowflake, tree, bush :: System
type Vertex
= (Float, Float)
type TurtleState
= (Vertex, Float)
type Stack
= [TurtleState]
type ColouredLine
= (Vertex, Vertex, Colour)
trace :: String -> Float -> Colour -> [ColouredLine]
trace rules angle colour = traceState rules ((0,0),90) []
where
traceState :: String -> TurtleState -> Stack -> [ColouredLine]
traceState [] _ _ = []
traceState (x:xs) t (y:ys)
|x == '[' = traceState xs t (t : (y:ys))
|x == ']' = traceState xs t ys
|x == 'F' = biggieSmalls : traceState xs t (nextY:ys)
|otherwise = traceState xs angledY (angledY:ys)
where
biggieSmalls = (fst(t),fst(nextY),colour)
nextY = move 'F' t angle
angledY = move x t angle