我有以下类型:
data Tree a = Empty |
Branch { key :: a,
balance :: Int8,
left :: Tree a,
right :: Tree a,
up :: Bool --used internally to stop updating balance
}
deriving (Eq)
以及与以下模式匹配的函数:
roll (Branch y (-2) l (Branch ry 1 (Branch rly 0 Empty Empty _) rr _) _) = ...
即使Empty Empty
里面(Branch rly 0 Empty Empty _)
是唯一可能的情况,我想知道 - 将表格概括为:
roll (Branch y 2 (Branch ly (-1) ll (Branch lry 0 lrl lrr _) _) r _) = ...
工作更快(甚至可以忽略不计),因为运行时不需要匹配lrl
和?lrr
Empty